How is the Java annotation processor implemented?

I am writing some kind of application in which I use an integer to represent various types of semantics. For example, I use int to represent both a month and a year, and I want to avoid accidentally using variables with one semantics in a context that requires another. I want to use annotation to annotate variables representing the month with @Monthand units representing the year with @Year, and would like the compiler to warn me if there is an unexpected purpose or method call. How to implement this?

BTW: I do not want to introduce additional classes Month and Year, because it is not so efficient and quite verbose in the syntax, for example. I need to call month.get()to use it where int is expected, and new Month(m)to create.

I tried to search the Internet but could not find enough document. Any ideas?

+4
source share

Source: https://habr.com/ru/post/1617663/


All Articles