Skip to content

Instantly share code, notes, and snippets.

@itang
Created June 20, 2012 05:16
Show Gist options
  • Save itang/2958251 to your computer and use it in GitHub Desktop.
Save itang/2958251 to your computer and use it in GitHub Desktop.
Trait - JsonObject
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