简体   繁体   中英

Refering to subclass from abstract class

i have a problem with my abstract class not knowing, which subclass calls its constructor.

abstract class A {

    Field field;

    public A() {
        this.field = Manager.add(Here i would like to add the type of subclass);
    }
}

I could carry the class-type as a parameter in a chain of constructors, but i was wondering if there is a different way.
Maybe I could use the StackTrace to find out about the subclasses and get their type, but i don't think it should be used this way.

Thank you very much in advance for your answers :)

this.getClass()将为您提供实例化的类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM