<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-2"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Igazad van, Bence, csak éppen azt mondta, hogy szeretné megfogni a tüzes vasat szabad kézzel, én meg javasoltam neki valami kenőcsöt utánára. De tényleg jobb, ha nem fogdosod. Valentin nap elmúlt.<div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="color: rgb(136, 136, 136); ">--</span><span class="Apple-style-span" style="color: rgb(136, 136, 136); "><br></span><span class="Apple-style-span" style="color: rgb(136, 136, 136); ">Verhás Péter</span><span class="Apple-style-span" style="color: rgb(136, 136, 136); "><br></span><span class="Apple-style-span" style="color: rgb(136, 136, 136); "></span><span class="Apple-style-span" style="color: rgb(136, 136, 136); "><a href="mailto:peter@verhas.com">peter@verhas.com</a></span><span class="Apple-style-span" style="color: rgb(136, 136, 136); "><br></span><span class="Apple-style-span" style="color: rgb(136, 136, 136); ">+36(30)9306805</span><span class="Apple-style-span" style="color: rgb(136, 136, 136); "><br></span><span class="Apple-style-span" style="color: rgb(136, 136, 136); ">skype: verhas</span></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></span><br class="Apple-interchange-newline">
</div>
<br><div><div>On 2013.02.15., at 17:44, <a href="mailto:coder@gmail.hu">coder@gmail.hu</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<div><p>Hali!</p><div>&nbsp;<br class="webkit-block-placeholder"></div><p>Én békénhagynám azt a ClassCastException -t, ugyanis - már amennyire nekem most ez lejön a kódból; pláne, így műszak végén :) - itt az a hunyó, aki Object mögé bújva nem megfelelő típusú példányt ad neked valahonnan (nem tudom, honnan jöhet az az Object kupac - nem lehet véletlenül ő is Collection&lt;T&gt; ?).</p><p>Innen nézve egy picit concerning, hogy Object típust kell valamire használni.</p><p>Ignore me if I've missed the point.</p><div>&nbsp;<br class="webkit-block-placeholder"></div><p>Üdv.: Bence</p><div>&nbsp;<br class="webkit-block-placeholder"></div><p>On Fri, 15 Feb 2013 09:57:32 +0100, Keresztes Jozsef wrote:</p>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<pre>Sziasztok !

A problémám a következő: 
Van egy interface-em:

public interface Predicate {
  public boolean match(T candidate);
}

És egy másik oszály query() metódusa pedig vár egy ilyen Predicate objektumot.

public  List query(Predicate predicate) {
  for (Object object: objects) {
    T t = (T)object;              // itt nincs hiba
    predicate.match(t);    // itt ClassCastException jöhet
  }
  ...
}

Ebben a másik osztályban van egy rakás Object, és szeretném meghívni a Predicate match() metódusát,
de csak azokkal az objektumokkal amelyek megfelelnek T-nek !
Persze rögtön az instanceof-ra gondolunk de azt nem lehet használni a subtype-ra.
Ráadásul a "T t = (T)object;" sem ad hibát még futásidőben sem pedig az objektum nem felel meg T-nek.
A futásidejű  ClassCastException csak akkor jön ha a match() meghívódik.
Szóval hogy lehetne megvizsgálni hogy egy objektum megfelel-e T típusnak és már a match()-nek
át se adjam ? 
A primítív megoldás az lehet hogy igenis minden objektumot átadok a match()-nek
és lekezelem egy try-blokkban a ClassCastException-t. Nincs jobb ?

Joe




_______________________________________________
Javalist mailing list
<a href="mailto:Javalist@lists.javaforum.hu">Javalist@lists.javaforum.hu</a>
<a href="http://lists.javaforum.hu/mailman/listinfo/javalist">http://lists.javaforum.hu/mailman/listinfo/javalist</a>
</pre>
</blockquote>
<div>&nbsp;</div>
</div>
_______________________________________________<br>Javalist mailing list<br><a href="mailto:Javalist@lists.javaforum.hu">Javalist@lists.javaforum.hu</a><br>http://lists.javaforum.hu/mailman/listinfo/javalist<br></blockquote></div><br></div></body></html>