摘录


In this example, we are going to show how we can use annotation processor to do validation and type checking during compile time. We are going to create an annotation DateFormat with a string parameter which would expect from developer to put a correct date format which can be parse to java.time.LocalDate. The processor will also check the type of annotated field, to confirm if it's not other than java.time.LocalDate. On validation failure it will send error message to the compiler, which will fail the whole compilation process. The idea is, during runtime the target field will be displayed on some screen or on a web page by some automatic logic which is expecting a correct date format on the annotation. This example will demonstrate how can we fix the problems during compile time rather than discovering the problems much later, during runtime.

We are going to create two projects. The first one will create the annotation processor and second one will be the client code using the annotation DateFormat

点评

NULL

原文

点击这里查看原文

其它

本帖内容由21QA云收藏工具自动生成,欢迎使用。

系统消息 若觉得内容不错,请点击左上角的"赞"图标,以优化网站的内容呈现。 另外,请及时验证注册邮箱,否则收不到21QA发出的红包。 官方Q群:250203055

asked 04 Jul, 16:51

%E8%B7%AF%E4%BA%BA%E7%94%B2's gravatar image

路人甲
131561594671

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link: [text](http://url.com/ "title")
  • image: ![alt](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×848
×69

question asked: 04 Jul, 16:51

question was seen: 34 times

last updated: 04 Jul, 16:51

powered by O*S*Q*A

粤ICP备14040061号-1