简体   繁体   中英

In Android (or Java itself), is it possible to a class to inherit from a class referenced by name?

Times ago, I was looking for a way to start ServiceMode programmatically. The great obstacle was how to understand the parameters that the class must receive (in its case, it is the SECRET CODES). And off course, the device must be rooted .

It had demanded plenty of research but I finally figured out how to start a system activity through command line. Now I want to create a class that extends from it. However, I don't have its API reference because it is hidded in Android internals and only accessible through things like reflection. I have only its name: com.sec.android.app.servicemodeapp.ServiceModeApp .

So, I'm wondering if Android/Java API let me create a class declaration in the form of:

public class MyCustomSystemActivity extends Class.forName("com.sec.android.app.servicemodeapp.ServiceModeApp") { ... }

Of course, this sentence is not allowed.

Can someone give me a hint if it is possible in other ways? And if yes, how can I declare such thing?

No, this is not possible. In a compiled language such as Java, the compiler needs to know what members are inherited and what methods are overridden, and it can't do this if it doesn't know what class is being extended.

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