简体   繁体   中英

Java Extend class based on object in constructor

What I would like to do is extend a class based on what is in the constructor. Is this possible? With my limited knowledge of java this would be the best example of what I'm trying to do.

public class Test extends extendClass {

    Object extendClass;

    public Test(Object extendClass){
        this.extendClass = extendClass;
    }

}

EDIT: What I would like is to have a sort of modular class that extends another class that is defined in the constructor I'm just using the constructor as an example. What I would be doing is running the code of the super class and then running mine as well. Also Object is just an example as well I know the class that I'm going to be extending.

Stuff like this should be possible with Aspect Oriented Programming, for which in Java there exists AspectJ. I wouldn't go there though if you're still a beginner in Java.

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