Scala Tutorialsを読む 30 Classes - continued
30 Classes - continued
30 クラスの続き
Uniform Access 統一アクセス
- Scala's getters and setters use the principle of uniform access, e.g. if you change the implementation of a field declared var name to a method def name you will not need to recompile the code
Scalaのゲッターとセッターは統一アクセス原理等を使っています。あなたが名前defメソッドにフィールド宣言したVAR名の実装を変更する場合は、コードを再コンパイルする必要はありません
Therefore there can't be a variable or method (def, val or var, private or public) that has the same name in a class
- そのため、そのクラスで同じ名前を持つ変数やメソッドが存在することはできません(def、valまたはvar、プライベートまたはパブリック)
Java style getters and setters Javaスタイルゲッター&セッター
- Scala's automatic getters and setters are following the uniform access principle, so the getter and setter name is the same as the field it encapsulates,
Scalaの自動ゲッターとセッターは統一アクセス原理をフォローしていて、ゲッターとセッターの名前は同じフィールドを包む。
However if you need to have Java client code accessing your Scala class, it's as easy as adding a @BeanProperty annotation to instruct the compiler to automatically add a Java bean style getter and setter.
しかしながら、JavaクライアントコードがScalaクラスにアクセスする場合は、簡単に@BeanPropertyアノテーションを追加出来る。指示通りにコンパイラにJavaビーンスタイルのゲッターとセッターを追加出来ます。
For boolean properties of style isFlag use @BooleanBeanProperty instead
- スタイルisFlagのブーリアンプロパティの代わりに@BooleanBeanPropertyを使う。
See Also opens in new page
新しいページを開いて参照
- More on Uniform Access Principle
- 統一アクセス原理の詳細