Advertisement
PaleoCrafter

Lazy reflection

Apr 17th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.40 KB | None | 0 0
  1. class Test {
  2.   var x = 0
  3.  
  4.   def test = x.toString
  5. }
  6.  
  7. val tpe = typeOf[Test]
  8. val ctor = tpe.constructor
  9. val x = tpe.fields.x[Int].unlocked
  10. val test = tpe.methods.test[String]
  11. val inst = ctor()
  12.  
  13. println(ctor)       // Constructor: Test()
  14. println(x)      // Field: Test#x: scala.Int
  15. println(test)       // Method: Test#test(): java.lang.String
  16. println(x.value(inst))  // 0
  17. x(inst) = 1
  18. println(test(inst)())   // 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement