J
joes
Hello
I am looking for a way in Java how I can test dynamically if an object
is from a given type or interface. Normally you can use the
"instanceof" operator but the operator requires a type information
which can not be a parameterized.
i.e.
//example1
boolean testIfSameType(Object o1, Object o2)
{
return (o1 instanceof o2); // ends in a compilation error
//examle2
boolean testIfSupportsType(Object o1, Class service)
{
return (o1 instance of service); // also of course not possible...
}
Before I like to spend some time to write my own "instanceof" I like
to hear if there are any other ways of some experts... i.e. new ways
in Java 1.5 ?
If I have to program myself I would go with Java reflection and
comparing the class names which is of course not efficient nor it is
easy to realise own support of automatical super typing (extended
interfaces and classes) and security management.
Exists there already some libraries which may provide my needed
functionality?
Any helpful hints or exeperiences are welcome...
Thank you regards
Mark Egloff
I am looking for a way in Java how I can test dynamically if an object
is from a given type or interface. Normally you can use the
"instanceof" operator but the operator requires a type information
which can not be a parameterized.
i.e.
//example1
boolean testIfSameType(Object o1, Object o2)
{
return (o1 instanceof o2); // ends in a compilation error
//examle2
boolean testIfSupportsType(Object o1, Class service)
{
return (o1 instance of service); // also of course not possible...
}
Before I like to spend some time to write my own "instanceof" I like
to hear if there are any other ways of some experts... i.e. new ways
in Java 1.5 ?
If I have to program myself I would go with Java reflection and
comparing the class names which is of course not efficient nor it is
easy to realise own support of automatical super typing (extended
interfaces and classes) and security management.
Exists there already some libraries which may provide my needed
functionality?
Any helpful hints or exeperiences are welcome...
Thank you regards
Mark Egloff