-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
d0d4368
commit 9f06aab
Showing
5 changed files
with
69 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"assignment":"java-spring-ru/first-start"} | ||
{"assignment":"java-spring-ru/annotations"} |
Empty file.
46 changes: 23 additions & 23 deletions
46
java-spring-ru/annotations/src/main/java/exercise/Application.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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package exercise; | ||
|
||
import exercise.model.Address; | ||
import exercise.annotation.Inspect; | ||
import java.lang.reflect.Method; | ||
|
||
public class Application { | ||
public static void main(String[] args) { | ||
var address = new Address("London", 12345678); | ||
|
||
// BEGIN | ||
for (var method : Address.class.getDeclaredMethods()) { | ||
if (method.isAnnotationPresent(Inspect.class)) { | ||
String result = "Method " + | ||
method.getName() + | ||
" returns a value of type " + | ||
method.getReturnType().getSimpleName(); | ||
System.out.println(result); | ||
} | ||
} | ||
// END | ||
} | ||
} | ||
package exercise; | ||
|
||
import exercise.model.Address; | ||
import exercise.annotation.Inspect; | ||
import java.lang.reflect.Method; | ||
|
||
public class Application { | ||
public static void main(String[] args) { | ||
var address = new Address("London", 12345678); | ||
|
||
// BEGIN | ||
for (var method : Address.class.getDeclaredMethods()) { | ||
if (method.isAnnotationPresent(Inspect.class)) { | ||
String result = "Method " + | ||
method.getName() + | ||
" returns a value of type " + | ||
method.getReturnType().getSimpleName(); | ||
System.out.println(result); | ||
} | ||
} | ||
// END | ||
} | ||
} |
28 changes: 14 additions & 14 deletions
28
java-spring-ru/annotations/src/main/java/exercise/annotation/Inspect.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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package exercise.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
// BEGIN | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface Inspect { | ||
|
||
} | ||
// END | ||
package exercise.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
// BEGIN | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface Inspect { | ||
|
||
} | ||
// END |
62 changes: 31 additions & 31 deletions
62
java-spring-ru/annotations/src/main/java/exercise/model/Address.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 |
---|---|---|
@@ -1,31 +1,31 @@ | ||
package exercise.model; | ||
|
||
import exercise.annotation.Inspect; | ||
|
||
public class Address { | ||
private String city; | ||
private int postalCode; | ||
|
||
public Address(String city, int postalCode) { | ||
this.city = city; | ||
this.postalCode = postalCode; | ||
} | ||
|
||
// BEGIN | ||
@Inspect | ||
// END | ||
public String getCity() { | ||
return city; | ||
} | ||
|
||
// BEGIN | ||
@Inspect | ||
// END | ||
public int getPostalCode() { | ||
return postalCode; | ||
} | ||
|
||
public String getFullAddress() { | ||
return city + " " + postalCode; | ||
} | ||
} | ||
package exercise.model; | ||
|
||
import exercise.annotation.Inspect; | ||
|
||
public class Address { | ||
private String city; | ||
private int postalCode; | ||
|
||
public Address(String city, int postalCode) { | ||
this.city = city; | ||
this.postalCode = postalCode; | ||
} | ||
|
||
// BEGIN | ||
@Inspect | ||
// END | ||
public String getCity() { | ||
return city; | ||
} | ||
|
||
// BEGIN | ||
@Inspect | ||
// END | ||
public int getPostalCode() { | ||
return postalCode; | ||
} | ||
|
||
public String getFullAddress() { | ||
return city + " " + postalCode; | ||
} | ||
} |