• 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.
  • Posts

  • Recent Achievements

    • Week One Done
      Helen Shafer earned a badge
      Week One Done
    • First Post
      emptyother earned a badge
      First Post
    • Week One Done
      Crunchy6 earned a badge
      Week One Done
    • One Month Later
      KynanSEIT earned a badge
      One Month Later
    • One Month Later
      gowtham07 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      665
    2. 2
      ATLien_0
      270
    3. 3
      Michael Scrip
      223
    4. 4
      Steven P.
      167
    5. 5
      +FloatingFatMan
      166
  • Tell a friend

    Love Neowin? Tell a friend!