The Artima Developer Community
Sponsored Link

Programming in Scala Forum
Listing 20.4 and surrounding..

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Martin Weber

Posts: 7
Nickname: ephaeton
Registered: Sep, 2008

Listing 20.4 and surrounding.. Posted: Nov 20, 2008 1:55 PM
Reply to this message Reply
Advertisement
Quote: "So the values of numerArg and denomArg are not available during the initialization of RationalTrait (more precisely, a selection of either value would yield the default value for type Int, 0) (...) If you try to instantiate this trait with some numerator and denominator expressions that are not simple literals, you'll get an exception: (...) The exception in this example was thrown because denomArg still had its default value of 0 when class RationalTrait was initialized, which caused the require invocation to fail."

Something's inconsistent here, I think it's the highlighted part that's simply wrong. Or put in other words: if the bold part (a selection of either value would yield 0) was true, it wouldn't make a difference if the given overriding definition was using "expressions that are not simple literals" because this way or another, the default value would be returned.

2.7.2.final actually agrees with the "imprecise" text: a literal is obviously accepted, an expression causes the value to be 'default' initialized and only bound later. Now if the 'precisely' speaking was correct, scala would be wrong; or vice versa.

(v6 btw)

Topic: Final version is...? Previous Topic   Next Topic Topic: 17.4 '+='

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use