Created
July 13, 2011 23:25
-
-
Save RSchulz/1081572 to your computer and use it in GitHub Desktop.
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
package rrs | |
trait Configurable | |
{ | |
val dir = "/foo/bar" | |
val env = "config1.cfg" | |
implicit val cde = (dir, env) | |
} | |
class Config(val name: String) | |
{ | |
def apply(sect: String)(param: String): String = | |
"%s|%s=<don't ask me>".format(sect, param) | |
} | |
object Config | |
{ | |
def config(file: String)(implicit de: (String, String)): Config = | |
new Config("%s<%s, %s>".format(file, de._1, de._2)) | |
} | |
class ConfigMe | |
extends Configurable | |
{ | |
import Config._ | |
val cfg = config("cf1.cfg") | |
val v1 = cfg("foo")("bar") | |
val v2 = config("cf1.cfg")("foo")("bar") | |
val v3 = (config("cf1.cfg"))("foo")("bar") | |
val v4 = config("cf1.cfg").apply("foo")("bar") | |
} | |
/* | |
Config.scala:32: error: type mismatch; | |
found : java.lang.String("foo") | |
required: (String, String) | |
val v2 = config("cf1.cfg")("foo")("bar") | |
^ | |
Config.scala:34: error: type mismatch; | |
found : java.lang.String("foo") | |
required: (String, String) | |
val v3 = (config("cf1.cfg"))("foo")("bar") | |
^ | |
two errors found | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment