![]() I have viewed answers here and here but have found that implementing the suggested fixes does not work, or that their issues do not apply to my situation. Java - Stream.reduce() Java - 2mergeputAll Java. I am confused because I know SuperClazz has a constructor that takes in three parameters, a String, a char and an int. NoSuchMethodError occurs when the code attempts to invoke an invalid method. NewSubInstance = oldSubInstance.getClass().getConstructor(String.class, char.class, int.class).newInstance("abc", 'e', 6) The type of error/exception thrown will depend on what the code is trying to do. This is my setup: private SuperClazz oldSubInstance I am trying to get whichever subclass this existing instance belongs to and make a new instance of that same subclass. ![]() I have an existing instance of one of these subclasses (declared only as a member of the super class, as I do not yet know which subclass it will belong to). parameterType which is the array of parameter type for the specified method. methodName which is the Method to be get. I am very new to Java so this may be a dumb question, but I am trying to understand how to create a new instance of a class by getting the class from an existing instance (I think this is called reflection).Ĭurrently I have a super class and several subclasses of it. Syntax: public Method getMethod (String methodName, Class parameterType) throws NoSuchMethodException, SecurityException. The getGenericSuperClass() method of java Class class returns a method object representing the specified public member method of the class or interface represented by this Class object.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |