We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e6e81d6 commit 81efdfaCopy full SHA for 81efdfa
tests/run/traitNoInit.scala
@@ -1,12 +1,29 @@
1
-trait Foo {
2
- //println("hello")
+trait NoInit {
+ def meth(x: Int): Int
3
+}
4
+
5
+trait WithInit {
6
+ val i = 1
7
def meth(x: Int): Int
8
}
9
10
trait Bar(x: Int)
11
-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) {
17
def meth(x: Int) = x
18
19
-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
0 commit comments