Class BytecodeUtility

java.lang.Object
org.gcube.informationsystem.utils.BytecodeUtility

public class BytecodeUtility extends Object
Reads facts from a class's own compiled bytecode that plain reflection cannot give a reliable answer to.
Author:
Luca Frosini (ISTI - CNR)
  • Method Details

    • readDeclaredMethodOrder

      public static List<String> readDeclaredMethodOrder(Class<?> clz)
      Returns the names of clz's own declared methods, in the order they appear in its compiled class file -- i.e. source declaration order, since javac preserves it in the method table. Class.getDeclaredMethods() cannot be used for this: its Javadoc explicitly makes no ordering guarantee ("not sorted and not in any particular order"), and in practice it does not preserve declaration order either.
      Parameters:
      clz - The class to read.
      Returns:
      The declared method names in class-file order, or an empty list if the class's bytecode could not be read (e.g. no classloader resource for it) -- never null, so a caller can safely fall back to another ordering for any name this list turns out not to contain.