Jay Taylor's notes
back to listing indexclass - Why is the Manifest not available in the constructor? - Stack Overflow
[web search]
Original source (stackoverflow.com)
Clipped on: 2012-09-25
Consider this code:
I basically want to store an identifier in Foo, which is often just the class name. Subclass which do not need a special identifier could then easily use the default value. But this doesn't even compile, the error message is:
Is there another approach which will work? EDIT: Why does this work if the manifest isn't available until the primary constructor?
| |||||||||
| |||||||||
When the syntactic sugar is removed from that context bound, it gets rewritten as:
So the Manifest evidence simply isn't available when determining the default value of
In your second approach (which is a great solution, by the way!), expect a rewrite similar to:
So yes, the manifest is available before the call to | |||||||||||||||||||||||||||||||||
|
Your Answer
community wiki