Created
May 4, 2015 16:44
-
-
Save polymorphic/1a9df44dd11949055fd7 to your computer and use it in GitHub Desktop.
Snippet illustrating how the object-protected modifier could cause the Scala compiler to generate code that throws ClassFormatError.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Code for illustrative purposes only, to demonstrate a particular behavior. | |
I already know that it doesn't run (throws ClassFormatError), and I wouldn't | |
write it this way to begin with :) | |
*/ | |
package eg | |
class Base() { | |
def foo = "bar" | |
} | |
trait Behavior { | |
val config = "base" | |
} | |
class Derived extends Base with Behavior { | |
/* | |
With the object-protected modifier the compiler generates code that causes a ClassFormatError to be thrown at | |
run time. | |
*/ | |
private[this] val config = "derived" | |
/* | |
Changing the modifier to private yields a compile error. | |
*/ | |
// private val config = "derived" | |
} | |
object Main extends App { | |
val instance = new Derived | |
instance.foo | |
println("done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment