Java array class members

The Reflexion API shows that any Java array class implements the java.lang.Cloneable and java.io.Serializable interfaces. He has no announced member.

My questions:

  • Where is this length defined?

  • If the protected Object clone () is redefined with a public access specifier using the type of the joint return option (byte [] replaces the object), since we can directly assign it to byte []?

  • If the association (IS-A) with Cloneable and Serializable is defined?

Also, the access specifier for the byte [] class contains an "abstract final", which is not a legal combination of any class or method in Java.

import java.lang.reflect.*; public class ArrayExplorer { public static void main(String[] args) { explore("Current class:", byte[].class); byte[] bytes = { 65, 'A' }; System.out.println(bytes.length); byte[] cloned = bytes.clone(); System.out.println(cloned); } private static void explore(String msg, Class<?> class1) { if (class1 == null) return; System.out.println("**************************************\n" + msg + Modifier.toString(class1.getModifiers()) + " " + class1); // if (class1 == Object.class) // return; Field[] fields = class1.getDeclaredFields(); for (Field field : fields) { System.out.println(field); } Method[] methods = class1.getDeclaredMethods(); for (Method method : methods) { System.out.println(method); } explore("Superclass:", class1.getSuperclass()); explore("Classes:", class1.getClasses()); explore("ComponentType:", class1.getComponentType()); explore("DeclaredClasses:", class1.getDeclaredClasses()); explore("DeclaringClass:", class1.getDeclaringClass()); explore("EnclosingClass:", class1.getEnclosingClass()); if (!class1.isInterface()) { explore("Interfaces:", class1.getInterfaces()); } } private static void explore(String msg, Class<?>[] classes) { if (classes == null || classes.length == 0) return; System.out.println(msg); for (Class<?> class1 : classes) { explore("", class1); } } } 
+4
source share
2 answers

Javoc

 getDeclaredMethods 

Returns an array of Field objects that reflect all the fields declared by the class or interface represented by this class object. This includes open, secure, default (batch) access, and private fields, but excludes inherited fields. The elements of the returned array are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface does not declare any fields, or if this class object represents a primitive type, an array class, or void.

 getDeclaredMethods 

Returns an array of Field objects that reflect all the fields declared by the class or interface represented by this class object. This includes open, secure, default (batch) access, and private fields, but excludes inherited fields. The elements of the returned array are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface does not declare any fields, or if this class object represents a primitive type, an array class, or void.

0
source

An array in java is a bit like a primitive: although Array.class exists to represent Array.class , in fact it does not have β€œcode” because the type is built directly into the language, therefore its fields, such as length , etc. unavailable when reflected.

0
source

All Articles