Marker Interface
Here is the 'marker' interface
-----------------------------------------------------
public interface IProblemChild{
}
-----------------------------------------------------
Here is the 'marked' class. It is marked by implementing
the IProblemChild interface.
-----------------------------------------------------
class AngusYoung implements IProblemChild{
}
-----------------------------------------------------
This is the test run. Notice that the some of the objects
in the array are 'marked' by implementing (being an instance
of) the IProblemChild interface.
This allows a program to treat these classes in a special
manner or to take some special action based on this
'mark'.
-----------------------------------------------------
class Test{
public static void main(String[] args){
System.out.println("class: Test, method: main");
Object[] myArray = new Object[5];
for(int i =0; i<myArray.length;i++){
if(i%2==0)
myArray[i]= new Integer(3);
else
myArray[i] = new AngusYoung();
}
for(int i =0; i<myArray.length;i++){
if(myArray[i] instanceof IProblemChild)
System.out.println("cause im a problem child");
}
}
}
-----------------------------------------------------
Here is a tar with the above java classes in it.
markerInterface.tar