Skip to content

Commit ede1859

Browse files
committed
Fix code samples in reflection overview
The code as is (`ru.typeOf[Person].decls(ru.nme.CONSTRUCTOR).asMethod`) gives an error: "reflect.runtime.universe.MemberScope does not take parameters"
1 parent 0cf9f94 commit ede1859

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

_ja/overviews/reflection/overview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Scala コンパイラが持つ型情報を全ては入手できない可能性
9191

9292
目的の `Type` のインスタンスが得られれば、これをインスペクトすることもできる。以下に具体例で説明しよう:
9393

94-
scala> val decls = theType.declarations.take(10)
94+
scala> val decls = theType.decls.take(10)
9595
decls: Iterable[ru.Symbol] = List(constructor List, method companion, method isEmpty, method head, method tail, method ::, method :::, method reverse_:::, method mapConserve, method ++)
9696

9797
#### ランタイム型のインスタンス化
@@ -118,7 +118,7 @@ Scala コンパイラが持つ型情報を全ては入手できない可能性
118118
次に、`reflectClass` メソッドを使って `Person` クラスの `ClassMirror` を取得する。
119119
`ClassMirror``Person` クラスのコンストラクタへのアクセスを提供する。
120120

121-
scala> val ctor = ru.typeOf[Person].declaration(ru.nme.CONSTRUCTOR).asMethod
121+
scala> val ctor = ru.typeOf[Person].decl(ru.nme.CONSTRUCTOR).asMethod
122122
ctor: scala.reflect.runtime.universe.MethodSymbol = constructor Person
123123

124124
`Person` のコンストラクタのシンボルは実行時ユニバース `ru` を用いて `Person` 型の宣言から照会することによってのみ得られる。
@@ -152,7 +152,7 @@ Scala コンパイラが持つ型情報を全ては入手できない可能性
152152
`shipped` メンバにアクセスするには、前の例と同じく、`p` のクラス (`Purchase`) を含むクラスローダが読み込んだ全てのクラスを入手可能とするミラー `m`
153153
を取得することから始める。
154154

155-
scala> val shippingTermSymb = ru.typeOf[Purchase].declaration(ru.TermName("shipped")).asTerm
155+
scala> val shippingTermSymb = ru.typeOf[Purchase].decl(ru.TermName("shipped")).asTerm
156156
shippingTermSymb: scala.reflect.runtime.universe.TermSymbol = method shipped
157157

158158
次に、`shipped` フィールドの宣言を照会して `TermSymbol` (`Symbol` 型の 1つ) を得る。

_overviews/reflection/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ The second step involves obtaining a `ClassMirror` for class `Person` using
132132
the `reflectClass` method. The `ClassMirror` provides access to the
133133
constructor of class `Person`.
134134

135-
scala> val ctor = ru.typeOf[Person].decls(ru.nme.CONSTRUCTOR).asMethod
135+
scala> val ctor = ru.typeOf[Person].decl(ru.nme.CONSTRUCTOR).asMethod
136136
ctor: scala.reflect.runtime.universe.MethodSymbol = constructor Person
137137

138138
The symbol for `Person`s constructor can be obtained using only the runtime
@@ -171,7 +171,7 @@ which makes all classes and types available that are loaded by the classloader
171171
that also loaded the class of `p` (`Purchase`), which we need in order to
172172
access member `shipped`.
173173

174-
scala> val shippingTermSymb = ru.typeOf[Purchase].decls(ru.TermName("shipped")).asTerm
174+
scala> val shippingTermSymb = ru.typeOf[Purchase].decl(ru.TermName("shipped")).asTerm
175175
shippingTermSymb: scala.reflect.runtime.universe.TermSymbol = method shipped
176176

177177
We now look up the declaration of the `shipped` field, which gives us a

0 commit comments

Comments
 (0)