Yes, you can do something similar quite easily. Okay you can't embed the rules into the language it's self but you can write code that will only perform certain tasks based on the what interfaces your Objects implement.
if instanceof my customMarkerInterface return true.
Message was edited by:
_helloWorld_
> Yes, you can do something similar quite easily. Okay
> you can't embed the rules into the language it's self
> but you can write code that will only perform certain
> tasks based on the what interfaces your Objects
> implement.
>
> if instanceof my customMarkerInterface return true.
>
> Message was edited by:
> _helloWorld_
There are no rules embedded in the language to deal with the marker interfaces that ship with the JDK, either. They're just interfaces like any other to the runtime. So you can write a marker interface that will work exactly like any other. The runtime treats classes outside of rt.jar exactly the same as the ones inside it
Here is a basic exmaple.
interface ExampleInterface {}
class ExampleInterfaceImpl implements ExampleInterface {
private boolean doSomething = false;
public void setDoSomething(boolean doSomething) {
this.doSomething = doSomething;
}
public void doIt() {
if(doSomething)
System.out.println("Look! I am doing it!");
}
}
public class Example {
public static void main(String[] args) {
ExampleInterfaceImpl exImpl = new ExampleInterfaceImpl();
if(exImpl instanceof ExampleInterface) {
exImpl.setDoSomething(true);
}
exImpl.doIt();
}
}
Hello George,
So where is the check performed for say the Serializable Interface? that says if Serializable then it can be Serialized?
Cheers
> Here is a basic exmaple.
>
> > interface ExampleInterface {}
>
> class ExampleInterfaceImpl implements
> ExampleInterface {
> private boolean doSomething = false;
>
> public void setDoSomething(boolean doSomething) {
> this.doSomething = doSomething;
> }
>
> public void doIt() {
> if(doSomething)
> System.out.println("Look! I am doing it!");
> }
> }
>
> public class Example {
>
> public static void main(String[] args) {
>
> ExampleInterfaceImpl exImpl = new
> ew ExampleInterfaceImpl();
>
> if(exImpl instanceof ExampleInterface) {
> exImpl.setDoSomething(true);
> }
>
> exImpl.doIt();
> }
> }
>
>
> Hello George,
>
> So where is the check performed for say the
> Serializable Interface? that says if Serializable
> then it can be Serialized?
>
> Cheers
Not in the JVM
> > Not in the JVM
>
> Does that mean "Not in the JVM" as in "I know because
> it is somewhere else" or "I don't know where but it
> is not in the JVM?"
It means I can't remember off the top of my head exactly where, but that Serializable is just a bunch of class bytes like any other, and the JVM gives classes in rt.jar a lot less special treatment than some people believe
> > > Not in the JVM
> >
> > Does that mean "Not in the JVM" as in "I know
> because
> > it is somewhere else" or "I don't know where but
> it
> > is not in the JVM?"
>
> It means I can't remember off the top of my head
> exactly where, but that Serializable is just a bunch
> of class bytes like any other, and the JVM gives
> classes in rt.jar a lot less special treatment than
> some people believe
Well I guess the check must be in ObjectOutputStream in that case.