简体   繁体   中英

How to add inheritance in a new class created by variable

Hello i used of answer in this question : Create new class from a Variable in Java to create by code a new class with name taked by variable. My question is how can i add inheritance to this new class?I already have the parent class and i want the new to be its child and inheritate all the methods.I've checked the Class Class in java.lang but it doesn't have something about setparent class or something like that.I understand that is very unsafe logic but i really want this feature in my application.Any ideas?

Just to clarify, and correct me if I'm wrong but are you trying to dynamically create a class that doesn't already exist or trying to instantiate an instance of a class from a String? Using classForName("Foo") is not going to create a new type that doesn't already exist, it's going to look through your classpath for a class named Foo and create an instance of its class object that you can then call methods on.

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