🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #2643

JAVA: Como saber que interfaz implementa un objeto?

#2643
From: Miguel Farah F.
Date: Wed, 19 Oct 2005 22:44
30 lines
1896 bytes
Tengo un m�todo en una clase que recibe como par�metro un objeto
*cualquiera*, y quiero hacer algunas cosas dependiendo de qu� cosa sea.
En particular, si corresponde a una clase que implemente java.util.List,
tiene que hacer ciertas cosas... y para eso debe saber reconocerlo.

Lo que arm�, y funciona, es esto (reemplacen la primera l�nea a
conveniencia):

Vector v=new Vector();
boolean implementaLista=false;
Class[] x=v.getClass().getInterfaces();
for (int k=0;k<x.length;k++) {
    if (x[k].toString().equals("interface java.util.List"))
        implementaLista=true;
}
System.out.println(implementaLista);

Me parece que la soluci�n (comparar strings) es poco elegante, y me
gustar�a tener algo mejor, pero no tengo claro c�mo hacer la comparaci�n
de marras de otra manera.

�Opiniones?

-- 
MIGUEL FARAH              //   NOmigSPuelAM@lj.cl
#include <disclaimer.h>   //   http://www.farah.cl
<*>
"Women! You can't live with them, you can't have heterosexual sex
 without them!"
- Dick Solomon, _3rd Rock From the Sun_
Technical Details
Message-ID: <4356be33@news.vcd.cl>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!news.vcd.cl!not-for-mail!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,367c655475693dfc,start
X-Google-Attributes: gid1593cb,public
X-Google-Language: SPANISH,ASCII
Message-ID: <4356be33@news.vcd.cl>
From: NOmigSPuelAM@lj.cl (Miguel Farah F.)
Subject: JAVA: Como saber que interfaz implementa un objeto?
Newsgroups: chile.comp.programacion
Organization: T.I.A.
User-Agent: tin/1.7.8-20050315 ("Scalpay") (UNIX) (Linux/2.4.27-2-686-antonia (i686))
NNTP-Posting-Host: antonia.lj.cl
X-Original-NNTP-Posting-Host: antonia.lj.cl
Date: 19 Oct 2005 18:44:19 -0400
X-Trace: news.vcd.cl!not-for-mail 1129758259 antonia.lj.cl (19 Oct 2005 18:44:19 -0400)
X-Original-Trace: 19 Oct 2005 18:44:19 -0400, antonia.lj.cl
Lines: 30
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!news.vcd.cl!not-for-mail!not-for-mail