This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Target(ElementType.METHOD) | |
@Retention(RetentionPolicy.RUNTIME) | |
@Documented | |
@Inherited | |
public @interface MethodInfo { | |
String author() default "Igor Brishkoski"; | |
int revision() default 1; | |
String comments(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyParentClass { | |
public void justaMethod() { | |
System.out.println("Parent class method"); | |
} | |
} | |
public class MyChildClass extends MyParentClass { | |
@Override | |
public void justaMethod() { | |
System.out.println("Child class method"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @deprecated | |
* reason for why it was deprecated | |
*/ | |
@Deprecated | |
public void anyMethodHere(){ | |
// Do something | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressWarnings("deprecation") | |
void myMethod() { | |
myObject.deprecatedMethod(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Target(ElementType.METHOD) | |
@Retention(RetentionPolicy.RUNTIME) | |
@Documented | |
@Inherited | |
public @interface MethodInfo { | |
String author() default "Igor Brishkoski"; | |
int revision() default 1; | |
String comments(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@MethodInfo(author = "John Snow", revision = 2, comments = "Hey!") | |
public void awesomeMethod() { | |
Method method = getClass().getMethod("awesomeMethod"); | |
MethodInfo methodInfo = method.getAnnotation(MethodInfo.class); | |
Log.d("MethodInfo", methodInfo.author()); | |
Log.d("MethodInfo", methodInfo.revision()); | |
Log.d("MethodInfo", methodInfo.comments()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//AwesomeApp | |
class User { | |
String firstName; | |
String lastName; | |
String city; | |
} | |
... | |
public class MainActivity extends AppCompatActivity { | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//our app build.gradle file | |
dependencies { | |
... | |
provided project(':annotation') | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// annotation module | |
package com.example.annotation; | |
@Target(ElementType.TYPE) //class level | |
@Retention(RetentionPolicy.SOURCE) //we only need it at compile time | |
public @interface AwesomeLogger {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AwesomeLogger | |
public class User { | |
String firstName; | |
String lastName; | |
String city; | |
} |
OlderNewer