View difference between Paste ID: 5XqNvwe6 and dsXDwZ2H
SHOW: | | - or go back to the newest paste.
1
// How to make field name "implicit" as if the class would extend String ?
2
trait Named { val name : String = "myself" }
3
class PersonOK extends Named { println( name.substring(0,2) )}
4-
class PersonKO extends Named { println( substring(0,2) )}
4+
class PersonKO extends Named { println( substring(0,2) )}
5
6
// The answer is :
7
class Person extends Named { import name._ ; println( substring(2) )}