User Tools

Site Tools


tutorial:reflection

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorial:reflection [2021/11/18 00:59] – created liachtutorial:reflection [2021/11/18 22:49] (current) – external edit 127.0.0.1
Line 34: Line 34:
 ===== Records ===== ===== Records =====
 Since 1.18, vanilla Minecraft starts using [[https://docs.oracle.com/en/java/javase/16/language/records.html|records]] in code. However, since Since 1.18, vanilla Minecraft starts using [[https://docs.oracle.com/en/java/javase/16/language/records.html|records]] in code. However, since
-Minecraft is processed by Proguard, which removes the record information from the Minecraft classes, these record classes will have such behaviors at runtime:+Minecraft is processed by Proguard, which removes the record information from the Minecraft classes, these record classes will have such behaviors at runtime, despite being decompiled as records in source:
 <code java> <code java>
 recordClass.isRecord() == false recordClass.isRecord() == false
Line 42: Line 42:
  
 See the JDK 17 API docs for [[https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Class.html#isRecord()|isRecord()]] and [[https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Class.html#getRecordComponents()|getRecordComponents()]]. See the JDK 17 API docs for [[https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Class.html#isRecord()|isRecord()]] and [[https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Class.html#getRecordComponents()|getRecordComponents()]].
 +
 +In addition, proguard also removes the signature (which indicates the generic information) from the record classes (but not from their methods). Yarn mappings defines signatures mappings for these classes. This affects reflection results on calls to some reflection methods, such as [[https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Class.html#getTypeParameters()|recordClass.getTypeParameters()]], and calling [[https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/reflect/Method.html#getGenericReturnType()|getGenericReturnType()]] on methods that refer to the absent type parameters on records may cause MalformedParameterizedTypeException.
tutorial/reflection.1637197153.txt.gz · Last modified: 2021/11/18 00:59 by liach