Skip to content

Instantly share code, notes, and snippets.

@ip-imamoto
ip-imamoto / ToDoTest.java
Created Feb 21, 2016
ToDoアノテーション使用クラス
View ToDoTest.java
package todo;
public class ToDoTest {
@ToDo(message = "if文が不要なので1行にまとめる", expiration = "20160211")
public static boolean over5characters(String target) {
if (target.length() > 5) {
return true;
}
@ip-imamoto
ip-imamoto / ToDoProcessor.java
Created Feb 21, 2016
ToDoProcessorクラス(コンパイル時の処理を記述)
View ToDoProcessor.java
package todo;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Set;
@ip-imamoto
ip-imamoto / ToDo.java
Created Feb 21, 2016
ToDoアノテーション
View ToDo.java
package todo;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
public @interface ToDo {
@ip-imamoto
ip-imamoto / MyAnnotationTest.java
Created Feb 21, 2016
アノテーションの使い方
View MyAnnotationTest.java
package myannotation;
public class MyAnnotationTest {
@MyAnnotation
public String hoge; //←valueの値の指定をしていないのでデフォルト値
@MyAnnotation(value = "コンストラクタ!!!") //←値を指定
public MyAnnotationTest(String hoge) {
this.hoge = hoge;
@ip-imamoto
ip-imamoto / MyAnnotation.java
Created Feb 21, 2016
アノテーションの定義方法
View MyAnnotation.java
package myannotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
@ip-imamoto
ip-imamoto / MyAnnotationTest.java
Created Feb 21, 2016
アノテーションとは
View MyAnnotationTest.java
package myannotation;
public class MyAnnotationTest {
@MyAnnotation //←こんなのとか
public String hoge;
@MyAnnotation(value = "コンストラクタ!!!") //←こんなのとか
public MyAnnotationTest(String hoge) {
this.hoge = hoge;
You can’t perform that action at this time.