• 0

Static Methods in Interfaces


Question

So basically I have a number of classes that i need to convert to and from bytes for networking purposes. So i created the interface:

public interface Raw
{
	public byte [] getBytes(); 
	public static Object fromBytes (byte [] data,int startPos) throws InvalidDataException;
}

The problem is that when i build it, i get told that static functions are illegal in interfaces.

Is there any way around this so that I can instanciate objects of the type that implements it through a common interface?

Link to comment
https://www.neowin.net/forum/topic/246352-static-methods-in-interfaces/
Share on other sites

6 answers to this question

Recommended Posts

  • 0
  liykh001 said:
yes why does it need to be static please do tell?

584959134[/snapback]

Well i think it's pretty logical at one stage i guess, an interfaces methods provides no implementation, and when you invoke a static method it's generally through ClassName.MethodName, but however i guess in some cases when developers want to create interfaces so that it forces the users of the interface to implement the method as being static would become an issue.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.