User Tools

Site Tools


zh_cn:tutorial:accesswideners

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
zh_cn:tutorial:accesswideners [2021/10/25 10:05] – [文件格式] solidblockzh_cn:tutorial:accesswideners [2021/10/25 10:14] (current) – [Access Wideners] solidblock
Line 1: Line 1:
-====== Access Wideners ======+====== 访问加宽 ======
  
-Access wideners(访问加宽)提供了一种放宽类、方法、字段访问权限的方式。Access wideners 类似于著名的 Access Transformers.+访问加宽(Access wideners)提供了一种放宽类、方法、字段访问权限的方式。访问加宽类似于著名的 Access Transformers.
  
-Access wideners 应该**仅在**使用 Mixin 无法实现时使用。目前只有以下两种情景 Mixin 无法做到:+访问加宽应该**仅在**使用 Mixin 无法实现时使用。目前只有以下两种情景 Mixin 无法做到:
   * 需要访问一个(包内)的私有类,尤其是为了 @Shadow 修饰或在 Mixin 类内访问一个字段或方法。   * 需要访问一个(包内)的私有类,尤其是为了 @Shadow 修饰或在 Mixin 类内访问一个字段或方法。
   * 需要重写使用 final 修饰的子类。   * 需要重写使用 final 修饰的子类。
Line 75: Line 75:
   - fieldDesc 是字段描述符   - fieldDesc 是字段描述符
  
-===== Access Changes =====+===== 访问权变更 =====
  
-=== Extendable ===+=== Extendable(可继承) ===
  
-Extendable should be used where you want to extend a class or override a method.+需要继承最终类或者覆盖最终方法时,用 extendable。
  
-  * Classes are made public and final is removed +  * 类将会改成 public 并移除 final 修饰符 
-  * Methods are made protected and final is removed+  * 方法会改成 protected 并移除 final 修饰符
  
-Making a method extendable also makes the class extendable.+将方法改为 extendable 的同时也会使类变为 extendable
  
-=== Accessible ===+=== Accessible(可访问) ===
  
-Accessible should be used when you want to access a class, field or method from another class.+需要访问另一个类的类、字段或方法时,用 accessible。
  
-  * Classes are made public +  * 类将变为 public 
-  * Methods are made public and final if private +  * 方法将变为 public,并且若为 private,还会变为 final 
-  * Fields are made public+  * 字段将会变为 public
  
-Making a method or field accessible also makes the class accessible.+将方法或者字段改为 accessible 将会使得类也 accessible
  
-=== Mutable ===+=== Mutable(可修改) ===
  
-Mutable should be used when you want to mutate a final field+需要修改常量字段时,用 mutable。
  
-  * Fields have final removed+  * 字段将会移除 final 修饰符
  
-===== Specifying file location =====+===== 指定文件位置 =====
  
-The access widener file location must be specified in your build.gradle and in your fabric.mod.json file. It should be stored in the resources as it needs to be included in the exported jar file.+访问加宽文件位置必须在 build.gradle 和 fabric.mod.json 文件中指定。该文件应该存在 resources 中,且需要包括在导出的 jar 文件中。
  
-Loom 0.9 or higher:+Loom 0.9 或更高版本:
  
 <code groovy [enable_line_numbers="true"]> <code groovy [enable_line_numbers="true"]>
Line 114: Line 114:
 </code> </code>
  
-Loom 0.8 or lower:+Loom 0.8 或更低版本:
  
 <code groovy [enable_line_numbers="true"]> <code groovy [enable_line_numbers="true"]>
Line 122: Line 122:
 </code> </code>
  
-fabric.mod.json:+fabric.mod.json
  
 <code json [enable_line_numbers="true"]> <code json [enable_line_numbers="true"]>
zh_cn/tutorial/accesswideners.1635156335.txt.gz · Last modified: 2021/10/25 10:05 by solidblock