Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2008

Tip: Looking for answers? Try searching our database.

Doubt on Generics and Interfaces

Thread view: 
Vinicius Cubas Brand - 06 Mar 2008 14:33 GMT
Hello. I have implemented an interface "ComboItem" and a class
implementing this interface, named "PortadorDireito". This class
"PortadorDireito" is abstract and is extended by the class
"Operador".

In another class, I have a method that receives a list of ComboItem,
like this:

import java.util.List;

class TesteAction {

  public void teste (String x, String y, List<ComboItem> options,
ComboItem default) {
  ...
  }

}

Then, when using this method TesteAction.teste(), I am passing a
List<Operador> as parameter, like this:

testeAction x = new TesteAction();
x.teste(String a, String b, List<Operador> c, Operador d)

The compiler is not accepting, so I must have done something wrong
with generics, or forgot to implement something. Do you have hints on
what I am doing wrong?

also the following gives error also, but different:

x.teste(String a, String b, List<Operador> c, null)

Below follow the error for the first case:

Caused by: java.lang.Error: Unresolved compilation problem:
    The method adicionarFiltroCombo(String, String, List, ComboItem,
String, boolean) in the type RelatorioAction is not applicable for the
arguments (String, String, List, Operador, String, boolean)

and for the second case:

Caused by: java.lang.Error: Unresolved compilation problem:
    The method adicionarFiltroCombo(String, String, List, ComboItem,
String, boolean) in the type RelatorioAction is not applicable for the
arguments (String, String, List, null, String, boolean)

Thank you.
Koos Pol - 06 Mar 2008 15:22 GMT
>    public void teste (String x, String y, List<ComboItem> options,
> ComboItem default) {

[snip]

> Caused by: java.lang.Error: Unresolved compilation problem:
>         The method adicionarFiltroCombo(String, String, List, ComboItem,

You're showning your method 'teste' but your error report is on
'adicionarFiltroCombo'.

Please repost with the *actual* method signature, the *actual* method
call, and the corresponding errors.

Cheers,
Koos
Daniel Pitts - 06 Mar 2008 15:28 GMT
> Hello. I have implemented an interface "ComboItem" and a class
> implementing this interface, named "PortadorDireito". This class
[quoted text clipped - 44 lines]
>
> Thank you.

If you need to take a list of things that extends ComboItem, then you
should accept List<? extends ComboItem> instead of just List<ComboItem>

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Hendrik Maryns - 06 Mar 2008 15:29 GMT
Vinicius Cubas Brand schreef:
> Hello. I have implemented an interface "ComboItem" and a class
> implementing this interface, named "PortadorDireito". This class
[quoted text clipped - 10 lines]
>    public void teste (String x, String y, List<ComboItem> options,
> ComboItem default) {

You’ll want List<? extends ComboItem> here, to be able to pass in
List<Operador>.  Read up on wildcards.

> Then, when using this method TesteAction.teste(), I am passing a
> List<Operador> as parameter, like this:
[quoted text clipped - 5 lines]
> with generics, or forgot to implement something. Do you have hints on
> what I am doing wrong?

Yes, see above: use wildcards.

> Caused by: java.lang.Error: Unresolved compilation problem:
>     The method adicionarFiltroCombo(String, String, List, ComboItem,
> String, boolean) in the type RelatorioAction is not applicable for the
> arguments (String, String, List, null, String, boolean)

You’re probably using Eclipse and executing a program that still has
compilation problems.  Solve them first.

Signature

Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Roedy Green - 15 Mar 2008 07:44 GMT
On Thu, 06 Mar 2008 16:29:21 +0100, Hendrik Maryns
<gtw37bn02@sneakemail.com> wrote, quoted or indirectly quoted someone
who said :

>You’ll want List<? extends ComboItem> here, to be able to pass in
>List<Operador>.  Read up on wildcards.

see http://mindprod.com/jgloss/generics.html#SYNTATICSOUP for a gentle
introduction.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

John B. Matthews - 15 Mar 2008 14:18 GMT
> On Thu, 06 Mar 2008 16:29:21 +0100, Hendrik Maryns
> <gtw37bn02@sneakemail.com> wrote, quoted or indirectly quoted someone
[quoted text clipped - 5 lines]
> see http://mindprod.com/jgloss/generics.html#SYNTATICSOUP for a gentle
> introduction.

Roedy:

I may have mistyped, but mail to feedback@mindprod.com bounces.

On page <http://mindprod.com/jgloss/generics.html#UGLY>, there  
appears to be a typographic error:

"// Somo ef the butt-ugly Generics syntax."

Not that I disagree:-)

Signature

John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews

Roedy Green - 28 Mar 2008 21:30 GMT
On Sat, 15 Mar 2008 09:18:59 -0400, "John B. Matthews"
<nospam@nospam.com> wrote, quoted or indirectly quoted someone who
said :

>I may have mistyped, but mail to feedback@mindprod.com bounces.

That should work.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 29 Mar 2008 00:04 GMT
On Fri, 28 Mar 2008 20:30:12 GMT, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :

>>I may have mistyped, but mail to feedback@mindprod.com bounces.
>
>That should work.

see http://mindprod.com/contact/contact.html
for some alternative ways of emailing me.

Anyway, I corrected the typo you found.  Thanks. There an army of
sharp-eyed people out there cleaning up after me.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.