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

add @constructor

上级 189ac9ee
......@@ -52,11 +52,11 @@ println(new TestClass(1, 2));
The `@json` scala macro annotation is the quickest way to add a JSON format to your Play project's case classes.
- Note
- This annotation is drawn from [json-annotation](https://github.com/kifi/json-annotation) and have some
optimization.
- It can also be used when there are other annotations on the case classes.
- Only an implicit `val` was generated automatically(Maybe generate a companion object if it not exists), and there are no other
operations.
- This annotation is drawn from [json-annotation](https://github.com/kifi/json-annotation) and have some
optimization.
- It can also be used when there are other annotations on the case classes.
- Only an implicit `val` was generated automatically(Maybe generate a companion object if it not exists), and there are no other
operations.
- Example
```scala
......@@ -78,10 +78,10 @@ Json.fromJson[Person](json)
The `@builder` used to generate builder pattern for Scala classes.
- Note
- Support `case class` / `class`.
- If there is no companion object, one will be generated to store the `builder` class and method.
- Currying is not supported in constructors at present.
- Support `case class` / `class`.
- If there is no companion object, one will be generated to store the `builder` class and method.
- Currying is not supported in constructors at present.
> IDE support is not very good, a red prompt will appear, but the compilation is OK. It only for the fields in the primary constructor
- Example
......@@ -138,7 +138,7 @@ object TestClass1 extends scala.AnyRef {
The `@synchronized` is a more convenient and flexible synchronous annotation.
- Note
- `lockedName` The name of the custom lock obj, default is `this`.
- `lockedName` The name of the custom lock obj, default is `this`.
- Support static and instance methods.
- Example
......@@ -178,8 +178,7 @@ The `@log` does not use mixed or wrapper, but directly uses macro to generate de
- `io.github.dreamylost.LogType.JLog` use `java.util.logging.Logger`
- `io.github.dreamylost.LogType.Log4j2` use `org.apache.logging.log4j.Logger`
- `io.github.dreamylost.LogType.Slf4j` use `org.slf4j.Logger`
- Support `class`, `case class` and `object`.
- Support `class`, `case class` and `object`.
> IDE support is not very good, a red prompt will appear, but the compilation is OK. You need to provide their dependencies and configuration, please refer to the test.
......@@ -212,6 +211,34 @@ The `@apply` used to generate `apply` method for primary construction of ordinar
println(B2(1, 2))
```
## @constructor
The `@constructor` used to generate secondary constructor method for classes.
- Note
- `verbose` Whether to enable detailed log.
- `excludeFields` Whether to exclude the specified `var` fields, default is `Nil`.
- Only support `class`.
- Currying is not supported for constructors at present.
- When used with `@toString`, it must be put last. Known problems.
> IDE support is not very good, a red prompt will appear, but the compilation is OK. You need to provide their dependencies and configuration, please refer to the test.
- Example
```scala
@constructor(excludeFields = Seq("c"))
class A2(int: Int, val j: Int, var k: Option[String] = None, t: Option[Long] = Some(1L)) {
private val a: Int = 1
var b: Int = 1 //The default value of the field is not carried to the apply parameter, so all parameters are required.
protected var c: Int = _
def helloWorld: String = "hello world"
}
println(new A2(1, 2, None, None, 100))
```
# How to use
Add library dependency
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册