• 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

    • Does the 4TB Crucial X10 still have the Data corruption issues that plague the previous generations?
    • Is the Start menu needed? Yes. Is it needed in its current form? No. I run lubuntu, it has all my apps sorted into categories, a bunch of preferences and system tools, the option to turn off, and search. It's all in a small rectangle and does everything you need it to.
    • Star Citizen Alpha 4.2 update lands with radiation hazards, dynamic rain, and more by Pulasthi Ariyasinghe The crowd-funded sci-fi RPG Star Citizen has received another update to its public alpha build. This time, developer Cloud Imperium Games has delivered new features like radiation as a brand-new hazard, irradiated creatures, the first implementation of a dynamic weather system for planets, and more. Dubbed Storm Breaker, Alpha update 4.2's cinematic trailer can be caught above, showing off the new sandbox activity. Storm Breaker is the name of the new sandbox activity too, continuing the ongoing Regen Crisis narrative. Players will be going to Pyro 1 and 4 while uncovering the experimentation secrets of the Associated Sciences & Development company while also weathering a never-ending storm, irradiated zones, and dangerous creatures to complete the event's tasks for hard-earned loot. Speaking of radiation, players will need to wear specialized gear and navigate carefully whenever they come across these special hazardous zones on planets. "This update adds new Radiation accumulation, resistance, and falloff thresholds to player status effects," says the developer. "These effects will appear as new visual and player status cues with REMs on the HUD and can cause consequences resulting in player injury or death if not treated." Locations on Stanton and Pyro planets can now have rain happen on them at various locations and times. Cloud Imperium calls this the first implementation of its Genesis: Dynamic Weather system. When ready, the full version of this tech will be rolling out to many more planets and will supposedly have rain and cloud formations, lightning, relevant audio, water pooling, and clothing shaders for wetness. Other changes of the update include better missile and torpedo tracking, new explorable locations, irradiated juvenile sandworms to fight, fixes for space stations and landing zones to reduce clipping and glitches, and much more. The complete release notes for the update can be found here. Star Citizen Alpha 4.2: Storm Breaker is now available for all backers in the Live channel.
  • Recent Achievements

    • Week One Done
      Wayne Robinson earned a badge
      Week One Done
    • One Month Later
      Karan Khanna earned a badge
      One Month Later
    • Week One Done
      Karan Khanna earned a badge
      Week One Done
    • First Post
      MikeK13 earned a badge
      First Post
    • Week One Done
      OHI Accounting earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      680
    2. 2
      ATLien_0
      269
    3. 3
      Michael Scrip
      209
    4. 4
      +FloatingFatMan
      170
    5. 5
      Steven P.
      148
  • Tell a friend

    Love Neowin? Tell a friend!