What does “reflective access of structural type member method should be enabled…” warning mean in Scala?

后端 未结 2 547
旧时难觅i
旧时难觅i 2021-01-04 01:59

After switching to Scala 2.10 I get tons of warnings:

reflective access of structural type member method ... should be enabled by making the implicit

2条回答
  •  旧巷少年郎
    2021-01-04 02:32

    From Scala Docs:

    Why control it? Reflection is not available on all platforms. Popular tools such as ProGuard have problems dealing with it. Even where reflection is available, reflective dispatch can lead to surprising performance degradations.

    Think about this code that uses an anonymous subclass:

    class Student(val id:Int)
    val specialStudent = new Student(0) {
       val greeting = "I am a special student with id " + id // Warning: id can be obfuscated
    } 
    

    Link to Scala Docs

提交回复
热议问题