<div dir="ltr"><p style="margin:0px 0px 10px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)">Sziasztok !</p><p style="margin:0px 0px 10px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)">
Valamit nagyon nem értek, persze lehet hogy a fától nem látom az erdőt :)<br>Van egy annotációm, a neve View. Amikor egy osztálynál vizsgálom hogy el van-e látva ezzel az annotációval,<br>kell egy &quot;számomra értelmetlen&quot; cast, különben a kód nem fordul le.<br>
Ha ugyanezt egy Field-nél vizsgálom, nem kell cast-olni. Az osztálynál miért kell ??? <br>Egyébként a dolog annotáció független, más annotációval is a helyzet ugyanez.</p><p style="margin:0px 0px 10px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)">
<br>Class cls = ...;<br>Field field = cls.getField(...);</p><p style="margin:0px 0px 10px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)">View view = (View)cls.getAnnotation(View.class); //??? mért kell cast ???<br>
View view2 = field.getAnnotation(View.class);</p><p style="margin:0px 0px 10px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)"> </p><p style="margin:0px 0px 10px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)">
Dokumentáció szerint a Class osztály getAnnotation() metódusa:</p><p style="margin:0px 0px 10px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)">public &lt;A extends Annotation&gt; A getAnnotation(Class&lt;A&gt; annotationClass)</p>
<p style="margin:0px 0px 10px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)">Dokumentáció szerint a Field osztály getAnnotation() metódusa:</p><p style="margin:0px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)">
public &lt;T extends Annotation&gt; T getAnnotation(Class&lt;T&gt; annotationClass)</p><p style="margin:0px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)">
<br></p><p style="margin:0px;padding:0px;font-size:13px;line-height:19px;color:rgb(0,0,0);font-family:Verdana;background-color:rgb(240,240,240)">Üdv, Joe</p></div>