Hi All,this is Prakash Is it possible to write custom markable interface,

Hi All,Is it possible to write custom markable interfaceThanks in advance
[87 byte] By [JeeDevelopera] at [2007-11-27 6:12:53]
# 1

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_

_helloWorld_a at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 2

> 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

georgemca at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 3
How Can We provide a behavior to a custom markable interface without providing any behavior like Serializable?Thanks in advance
JeeDevelopera at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 4

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

_helloWorld_a at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 5
> How can we provide a behavior without providing any behavior ?What?
corlettka at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 6
> > How can we provide a behavior without providing any> behavior ?> > What?Don't you know the sound of one hand clapping?
georgemca at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 7

> 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

georgemca at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 8
> Don't you know the sound of one hand clapping?Yeah, wasn't that by the Dead Kennedy's :-)
corlettka at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 9
> Not in the JVMDoes 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?"
_helloWorld_a at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 10

> > 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

georgemca at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 11
Thanks
JeeDevelopera at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...
# 12

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

_helloWorld_a at 2007-7-12 17:20:32 > top of Java-index,Java Essentials,Java Programming...