提交 5e37ee04 编写于 作者: 梦境迷离's avatar 梦境迷离

update README.md

上级 a1bbfa98
......@@ -9,17 +9,41 @@ scala macro and abstract syntax tree learning code.
- Contains constructor parameters which have `val`/`var` modifier and class internal fields.
- The existing custom `toString` method will fail to compile.
- source code
- source code1
```scala
@toString
@toString(isContainsCtorParams = true)
class TestClass(val i: Int = 0, var j: Int) {
val y: Int = 0
var z: String = "hello"
var x: String = "world"
}
// result of scalac
class TestClass extends scala.AnyRef {
<paramaccessor> val i: Int = _;
<paramaccessor> var j: Int = _;
def <init>(i: Int = 0, j: Int) = {
super.<init>();
()
};
val y: Int = 0;
var z: String = "hello";
var x: String = "world";
override def toString(): String = scala.collection.immutable.List(i, j, y, z, x).toString.replace("List", "TestClass") // a crude way, TODO refactor it.
}
//println(new TestClass(1, 2))
//TestClass(1, 2, 0, hello, world)
```
- result of scalac
- source code2
```scala
@toString
class TestClass(val i: Int = 0, var j: Int) {
val y: Int = 0
var z: String = "hello"
var x: String = "world"
}
// result of scalac
class TestClass extends scala.AnyRef {
<paramaccessor> val i: Int = _;
<paramaccessor> var j: Int = _;
......@@ -30,7 +54,9 @@ class TestClass extends scala.AnyRef {
val y: Int = 0;
var z: String = "hello";
var x: String = "world";
override def toString(): String = scala.collection.immutable.List(i, j, y, z, x).toString.replace("List", "TestClass") // a crude way, TODO refactor it.
override def toString(): String = scala.collection.immutable.List(y, z, x).toString.replace("List", "TestClass") // a crude way, TODO refactor it.
}
//println(new TestClass(1, 2))
//TestClass(0, hello, world)
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册