Why is casting the class of a generic to Class unsafe?

后端 未结 3 1193
再見小時候
再見小時候 2021-01-13 05:24

I\'m making a MethodPointer class in order to simulate the functionality of function pointers from C++. At first, I was doing everything with just Object

3条回答
  •  情歌与酒
    2021-01-13 06:00

    If you do not need an specified Class-type, you could use

    Class
    

    for you parameters.

    So you have an unbound Type for your classes.

    And if you want to get an instance you could use it like this:

    obj.getClass().getDeclaredConstructor(Class parameterTypes)
    

提交回复
热议问题