equivalent of "TypeOf" keyword of .NET in JAVA

Discussions

General J2EE: equivalent of "TypeOf" keyword of .NET in JAVA

  1. equivalent of "TypeOf" keyword of .NET in JAVA (3 messages)

    could any please tell me the equivalent of "TypeOf" keyword in .NET in JAVA

    Thanksin ADV
    Kasha
  2. The equivalent to the TypeOf keyword is the class literal as defined here.

    You can also use the getClass() instance method to obtain the Class of a specific object.

    public class MyClass
    {
       public int intI;
       public void MyMeth()
       {
       }

       public static void main(String[] arg)
       {
          Class c = MyClass.class;

          // alternatively, you could use
          MyClass t1 = new MyClass();
          Class c2 = t1.getClass();

          Method[] methods= c.getMethods();
          ....

          Field[] field= c.getFields();
          ....
       }
    }

    For more info on the java.lang.Class type, look at the JavaDoc for your JDK.
  3. In simple terms if...

    in .NET
    setDBColumn("ColName", TypeOf(String));

    then in Java
    setDBColumn("ColName", String.class);
  4. Did you try instanceof[ Go to top ]

    Try instanceof in java to getsomewhat equivalent for it.