Definition:
List<Method> declaredMethods = Arrays.asList(entityClass.getDeclaredMethods());
Operation:
declaredMethods.remove(method);
Throw:
Exception in thread "main" java.lang.UnsupportedOperationException
Why is this happening? Because we think that JDK will return an ArrayList or sorted list, the remove (int index) method is called directly. What is actually returned by asList? AsList returns a subclass of the custom AbstractList In the Arrays class, which does not implement the remove Method.
Solution: change the definition:
List <Method> declaredMethods = new ArrayList <> ();
DeclaredMethods. addAll (Arrays. asList (entityClass. getDeclaredMethods ()));
Or:
List <Method> declaredMethods = new ArrayList <> (Arrays. asList (entityClass. getDeclaredMethods ()));
Summary: The Arrays class does not implement the remove method because it is a subclass of the custom AbstractList class.
Therefore, to completely convert the array and Variable Parameter objects to the container type, you must use the AddAll ()
Or use the constructor to achieve the goal.
This article is from "welcone !" Blog. For more information, contact the author!