Java - Pass Class as Parameter for Comparison -


essentially want pass class parameter can preform instanceof comparison.

public class myclass {     object o = something;      public void mymethod(class c)     {         if(o instanceof c)         {                     }     } } 

where parameter class c class choose pass in else where. want able pass in class , make comparison.

any appreciated.

thanks

you can call class#isinstance(object obj):

if(c.isinstance(o)) { 

determines if specified object assignment-compatible object represented class. this method dynamic equivalent of java language instanceof operator.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -