Scala中格式错误的类名

时间:2017-10-25 05:02:27

标签: scala

为什么我在REPL中收到格式错误的类名错误?

定义父类

scala> class Fruit {
     | def FruitMethod = "f"
     | }
defined class Fruit

定义子类

scala> class Orange extends Fruit {
     | def OrangeMethod = "o"
     | }
defined class Orange

测试差异

scala> class MyContainer[+A](val a: A)(implicit manifest: scala.reflect.Manifest[A]) {
     |   def contents = manifest.runtimeClass.getSimpleName
     | }
defined class MyContainer

scala> val fruitBasket: MyContainer[Fruit] = new MyContainer[Orange](new Orange())
fruitBasket: MyContainer[Fruit] = MyContainer@7546be68

scala> fruitBasket.contents
java.lang.InternalError: Malformed class name
  at java.lang.Class.getSimpleName(Class.java:1330)
  at MyContainer.contents(<console>:13)
  ... 29 elided

0 个答案:

没有答案