Can you inspect the byte code of a Java 8 lambda at runtime?

后端 未结 4 1953
夕颜
夕颜 2021-01-31 18:22

If you have an anonymous class like

Predicate isEmpty = new Predicate() {
    public boolean test(String t) {
        return t.isEmpt         


        
4条回答
  •  [愿得一人]
    2021-01-31 18:56

    If you just want to SEE the bytecode:

    javap -c -p -v classfile
          ^disassemble
             ^private methods
                ^verbose, including constant pool and bootstrap methods attribute
    

    But if you want to try to do this at runtime, you're pretty much out of luck (by design, we don't have anything like Expression Trees), as the other answer suggests.

提交回复
热议问题