Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null interface

 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does Java has an official term called Null Interface? I have read in some java forums that an interface without any method listing. Is that true?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. An interface with no methods is generally called a marker interface. And there's a lot of discussion about why marker interfaces are now considered a bad idea; you can find these using our search feature. Anyone calling this concept a "null interface" is creating needless confusion by using nonstandard, misleading terminology.
 
Matthew Alesi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no actual term "null interface." What you might be referring to is a marker interface, which is indeed an interface defined with no actual methods to implement.

One of the most well-known examples is Serializable. When you implement Serializable, you do not have to actually implement any methods; you are simply telling the JVM that this class is allowed to be serialized. Another example is the Java 5 addition RandomAccess, which is implemented by ArrayList (and other classes) to signify that it provides effecient ( O(1) ) access to its elements.

So that's all there is to "null" interfaces.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaIntermediateFaq has an entry on marker interfaces.
 
Nirmal Mekala Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you all very much for clearing the clouds
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic