Skip to content

Commit

Permalink
submit java-spring-ru/annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
hexlet-cli committed Feb 16, 2024
1 parent d0d4368 commit 9f06aab
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .current.json
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 modified java-spring-ru/annotations/gradlew
100644 → 100755
Empty file.
46 changes: 23 additions & 23 deletions java-spring-ru/annotations/src/main/java/exercise/Application.java
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
}
}
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
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;
}
}

0 comments on commit 9f06aab

Please sign in to comment.