Re: How to get the runtime class?



Yeah, sorry the bug was elsewere :)

Abhijat Vatsyayan wrote:

Have you even tried compiling and running the  example  you have posted?

A few things -

* type of "c" will always be java.lang.Class .
* c.getName() can never return foo (or its fully qualified name). foo is an abstract
class.
* "this" will always refer to an object . If the object is of type foo2,
this.getClass().getName() will return foo2 (FQN really ) . There is no "this" at a class
level in java since class of an object is not really an object (in any interesting/OO
way) in  java. Class of an object will always be an object of type java.lang.Class.
* Children object and parent object ? Are you talking inheritence or some kind of
composition ? If you wan to find out all subclasses of a given class, the simple answer
is -  you can not. You can  however find out super class or super interface(s) using
reflection.


Fredy wrote:


I have 2 classes

abstract public class foo {

       public void bar() {

               // i want a Class object of "this"

               Class c = this.getClass(); // here i get a class of type foo, even if
the runtime class is type foo2
       }
}

public class foo2 extends foo {

...
}

with other words, how to get the children object from the parent object?


.



Relevant Pages

  • Re: Java Instanz und Objekt frage ?
    ... >>>fully qualified name der Klasse.Wenn du jetzt diesen Namensraum nimmst ... > laut VM ist der FQN von Foo Foo und nicht .Foo. .Foo ist ein ungültiger ... einem gedankenexperiment die Sprache Java' vorzustellen, ... Nochmal: die Transformation geht so: ...
    (de.comp.lang.java)
  • Re: On Symbols
    ... Have any of the explanations in the thread (What is the difference between:foo and "foo" ?) helped you understand symbols? ... For example, a Lisp symbol can also be bound to a value, a property list, or a function. ... I do know what a string is, and the definition of "interned" is supplied. ... I don't know Java. ...
    (comp.lang.ruby)
  • Re: CLOS and databases
    ... > define macros that can use type information (something that Common ... in my interpreter I've used the Java bean conventions to map accessors, ... It only tries getFoo() and isFooif foois undefined. ... either the handler for the signalling thread is null or the no handler ...
    (comp.lang.lisp)
  • Re: Perl data types
    ... :>> As for sum types, ... This can take several forms but again in the example of a java. ... If they are Foo objects, then why pretend they are just generic Objects? ... : "bar" method. ...
    (comp.lang.perl.misc)
  • Re: cc-mode, JDE, and defun-block-intro
    ... > public static void main(Stringargs) ... > // Foo testing here ... In the Java example, you want function ...
    (comp.emacs)