Main.scala:
package controler
object Main {
def main(args: Array[String]) {
import Utilites._
isJavaUpToDate
}
}
Utilites.scala:
package controler
object Utilities {
def isJavaUpToDate = {
val javaVersion = augmentString(System.getProperty("java.version").substring(2, 3))
javaVersion >= 6
}
}
Why isn’t this working?
I have been trought a bunch of differenet tutorial sites where this works no problem.
I always says that val Utilites cannot be found.
P.S. Why does it keep sugesting me to change .toInt with augmentString() when it just breaks the code?
Now this gives me trouble, something about implicit ordering and method orderTOOrdered.
Note that by calling
augmentStringyou’re explicitly transforming your string to a StringOps.StringOps does define a
>=method, but it’s meant to compare strings (its signature isdef >=(that: String): Boolean)If you want to compare Ints you should use the
toIntmethod defined inStringOps.Also, unless you need to disambiguate the
toIntagainst another implicit that you defined (or is defined somewhere else in a library you’re using) there should be no need to call augmentString explicitly. The following should just work (unless the compiler tells you it does not) and it should implicitly have the same effect as the code above of transforming yourStringto aStringOps.EDIT: as per @som-snytt’s comment
The error you’re getting (
No implicit Ordering defined for AnyVal) is due to the compiler reasoning more or less like this:javaVersion >= 6meansjavaVersion.>=(6), i.e. I must look for a method called>=on javaVersion that takes an integerjavaVersionis aStringOps… there is a>=method in StringOps (courtesy of theStringLiketrait it’s extending, that in turn extendsOrdered[String]) but it takes a String argument, not an IntOrderingforStringOps. Now, since you’re trying to compare aStringwith aIntyou’re looking at anOrderingthat can compare two values with the nearest common ancestor that can contain bothStringandInt, i.e.AnyVal[EDIT: although String is an AnyRef so I don’t really get this part…].AnyVals