Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object o = new Long[0]
- System.out.println( o.getClass().isArray() )
- System.out.println( o.getClass().getName() )
- Class ofArray = ???
- true
- [Ljava.lang.Long;
- Class ofArray = o.getClass().getComponentType();
- public <T> Class<T> testArray(T[] array) {
- return array.getClass().getComponentType();
- }
- Object maybeArray = ...
- Class<?> clazz = maybeArray.getClass();
- if (clazz.isArray()) {
- System.out.printf("Array of type %s", clazz.getComponentType());
- } else {
- System.out.println("Not an array");
- }
- String[] arr = {"Daniel", "Chris", "Joseph"};
- arr.getClass().getComponentType(); // => java.lang.String
Add Comment
Please, Sign In to add comment