Created
June 20, 2012 05:16
-
-
Save itang/2958251 to your computer and use it in GitHub Desktop.
Trait - JsonObject
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
trait Lang{ | |
def name: String | |
} | |
def jsonObject[T](json: String)(implicit t: Manifest[T]) { | |
//运行时创建T的子类、实现方法获取json属性的逻辑、加载类 | |
//并且实例化 | |
} | |
Lang lang = jsonObject[Lang]("{name:'test'}") | |
lang.name | |
// 另外的思路使用macro | |
//参考资料 | |
/* | |
http://stackoverflow.com/questions/10373318/mixing-in-a-trait-dynamically/10387200#10387200 | |
http://stackoverflow.com/questions/3254232/dynamic-mixin-in-scala-is-it-possible/3269452#3269452 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment