File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change 1
- trait Foo {
2
- // println("hello")
1
+ trait NoInit {
2
+ def meth (x : Int ): Int
3
+ }
4
+
5
+ trait WithInit {
6
+ val i = 1
3
7
def meth (x : Int ): Int
4
8
}
5
9
6
10
trait Bar (x : Int )
7
11
8
- class C extends Foo () with Bar (1 ) {
12
+ class NoInitClass extends NoInit () with Bar (1 ) {
13
+ def meth (x : Int ) = x
14
+ }
15
+
16
+ class WithInitClass extends WithInit () with Bar (1 ) {
9
17
def meth (x : Int ) = x
10
18
}
11
19
12
- object Test extends C with App
20
+ object Test {
21
+ def hasInit (cls : Class [_]) = cls.getMethods.map(_.toString).exists(_.contains(" $init$" ))
22
+ def main (args : Array [String ]): Unit = {
23
+ val noInit = new NoInitClass {}
24
+ val withInit = new WithInitClass {}
25
+
26
+ assert(! hasInit(noInit.getClass))
27
+ assert(hasInit(withInit.getClass))
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments