Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Scala での次の Java メソッド宣言に相当するものは次のとおりです。
public <T> T readValue(java.lang.String s, java.lang.Class<T> tClass)
つまり、T 型のクラスを受け取り、その型のインスタンスを返すメソッドを宣言したいと考えています。
I.あなたが望むものに非常に近い:
def readValue[T:ClassTag](s:String):T = { val tClass = implicitly[ClassTag[T]].runtimeClass //implementation for different classes. }
使用法は Java よりも少し明確です。
val myDouble = readValue[Double]("1.0")