|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Messaggi: n/a
|
java e annotazioni ripetibili
ciao ragazzi domanda piuttosto ostica (almeno per me)
data questa annotazione che in un certo programa viene ripetuta due volte con valori diversi Codice:
@Repeatable(TestTriggers.class)
public @interface TestTrigger {
String quando();
StrumentoDiTest come() default StrumentoDiTest.JUNIT; public enum StrumentoDiTest { JUNIT, GUI, JMETER, SOAPUI; } }
Codice:
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
public @interface TestTriggers {
TestTrigger[] value();
}
Codice:
Class<TestRepeatable> testRepeatableClass = TestRepeatable.class;
TestTriggers [] annotations = testRepeatableClass.getAnnotationsByType(TestTriggers.class);
for (TestTriggers testTriggers: annotations)
{ TestTrigger[] values = testTriggers.value();
for(TestTrigger testTrigger: values)
{ System.out.println(testTrigger.quando());
System.out.println(testTrigger.come());
}
}
la domanda è questa... questo comando TestTriggers [] annotations = testRepeatableClass.getAnnotationsByType(TestTriggers.class); perchè necessita di un array? cioè il TestTriggers contenitore non è uno soltanto? io pensavo fosse così, ovvero TestTrigger senza s TestTrigger [] annotations = testRepeatableClass.getAnnotationsByType(TestTriggers.class); for(TestTrigger testTrigger: annotations) { System.out.println(testTrigger.quando()); System.out.println(testTrigger.come()); potete aiutarmi please? insomma cosa mi da getAnnotationsByType Ultima modifica di vittorio130881 : 08-01-2015 alle 17:50. |
|
|
|
#2 |
|
Senior Member
Iscritto dal: Jun 2014
Messaggi: 3753
|
|
|
|
|
|
|
#3 |
|
Messaggi: n/a
|
dead ma non è che ti sei iscritto al forum per rispondere PERFETTAMENTE alla mia domanda?? hahahahaha grazie mille sei un mito
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Jun 2014
Messaggi: 3753
|
Prego
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 16:21.



















