-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>days</artifactId> | ||
<groupId>com.thegreatapi.100daysofjava</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>day087</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>16</maven.compiler.source> | ||
<maven.compiler.target>16</maven.compiler.target> | ||
</properties> | ||
|
||
</project> |
33 changes: 33 additions & 0 deletions
33
days/day087/src/main/java/com/thegreatapi/ahundreddaysofjava/day087/Day087.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.thegreatapi.ahundreddaysofjava.day087; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
public class Day087 { | ||
|
||
public static void main(String[] args) { | ||
var myAnnotatedObject = new AnnotatedClass(); | ||
var myNonAnnotatedObject = new NonAnnotatedClass(); | ||
|
||
System.out.println(isAnnotated(myAnnotatedObject)); // Prints: true | ||
System.out.println(isAnnotated(myNonAnnotatedObject)); // Prints: false | ||
} | ||
|
||
private static boolean isAnnotated(Object object) { | ||
return object.getClass().isAnnotationPresent(MyAnnotation.class); | ||
} | ||
|
||
@MyAnnotation | ||
static class AnnotatedClass { | ||
} | ||
|
||
static class NonAnnotatedClass { | ||
} | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@interface MyAnnotation { | ||
} | ||
} |
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