NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Re: Map<String, ?>

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
jyeary



Joined: 21 Oct 2008
Posts: 610
Location: Simpsonville, SC

PostPosted: Tue Jun 08, 2010 2:04 pm    Post subject: Re: Map<String, ?> Reply with quote

The implication is that you want to use generics. If you use Map() it is expecting Map(Object x, Object y) by default. In your case you are using Map<String ,y>(), you need to tell the compiler what y is. If you use one generic (String), you must tell the compiler what the second element is going to be, even if it is an Object. Try Map<String, Object>().


On Tue, Jun 8, 2010 at 6:29 AM, Jose Alvarez de Lara <address-removed ([email]address-removed[/email])> wrote:
Quote:
Hi,
Back to top
pepelara



Joined: 29 Nov 2008
Posts: 115

PostPosted: Tue Jun 08, 2010 4:51 pm    Post subject: Re: Map<String, ?> Reply with quote

Thanks for your help John.

You say I try Map<String, Object>, but I can't. In this case Map<String, ?> is a parameter of the initialize() method of the JASS LoginModule.

I am trying to assign a value to this Map for a String key but I do not find the solution. The only explanation I guess is that this parameter is an input parameter and
it is not possible to change it. The reference of LoginModule says this argument is used to pass another LoginModule.

This is taking me a week to do login but I do not find the solution. I am trying a jdbcRealm against GF v3 and MySQL

Any suggestion?

Thanks again,
Jose


From: John Yeary ([email]address-removed[/email])
Sent: Tuesday, June 08, 2010 4:03 PM
To: nbj2ee ([email]address-removed[/email])
Subject: [nbj2ee] Re: Map<String, ?>




The implication is that you want to use generics. If you use Map() it is expecting Map(Object x, Object y) by default. In your case you are using Map<String ,y>(), you need to tell the compiler what y is. If you use one generic (String), you must tell the compiler what the second element is going to be, even if it is an Object. Try Map<String, Object>().


On Tue, Jun 8, 2010 at 6:29 AM, Jose Alvarez de Lara <address-removed ([email]address-removed[/email])> wrote:
Quote:
Hi,

What does Map<String, ?> mean?

I need to do,

Map<String, ?> options; // for an already instantiated Map
options.put("someString", someObject)

but the compiler does not let me.

Any suggestion about how does it work will be appreciated!!!

Regards,
Jose




--
John Yeary
--
http://javaevangelist.blogspot.com

"Far better it is to dare mighty things, to win glorious triumphs, even though checkered by failure, than to take rank with those poor spirits who neither enjoy much nor suffer much, because they live in the grey twilight that knows not victory nor defeat."
-- Theodore Roosevelt
Back to top
jyeary



Joined: 21 Oct 2008
Posts: 610
Location: Simpsonville, SC

PostPosted: Tue Jun 08, 2010 7:47 pm    Post subject: Re: Map<String, ?> Reply with quote

Take a look at this

http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

You may be encountering something like Map<String, ?> map = new HashMap<String, String>(); This creates a map which does not allow you to add elements.

map.add("Hello", "World"); // Compile time error.


On Tue, Jun 8, 2010 at 12:51 PM, Jose Alvarez de Lara <address-removed ([email]address-removed[/email])> wrote:
Quote:
Thanks for your help John.
Back to top
pepelara



Joined: 29 Nov 2008
Posts: 115

PostPosted: Thu Jun 10, 2010 12:25 am    Post subject: Re: Map<String, ?> Reply with quote

Thanks John for your kind help.
You are right.

This map is an input parameter of a method. You can set your private field to this parameter to read it later.
I think that is the reason it is defined this way.

Best Regards,
Jose


From: John Yeary ([email]address-removed[/email])
Sent: Tuesday, June 08, 2010 9:47 PM
To: nbj2ee ([email]address-removed[/email])
Subject: [nbj2ee] Re: Map<String, ?>




Take a look at this

http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

You may be encountering something like Map<String, ?> map = new HashMap<String, String>(); This creates a map which does not allow you to add elements.

map.add("Hello", "World"); // Compile time error.


On Tue, Jun 8, 2010 at 12:51 PM, Jose Alvarez de Lara <address-removed ([email]address-removed[/email])> wrote:
Quote:
Thanks for your help John.

You say I try Map<String, Object>, but I can't. In this case Map<String, ?> is a parameter of the initialize() method of the JASS LoginModule.

I am trying to assign a value to this Map for a String key but I do not find the solution. The only explanation I guess is that this parameter is an input parameter and
it is not possible to change it. The reference of LoginModule says this argument is used to pass another LoginModule.

This is taking me a week to do login but I do not find the solution. I am trying a jdbcRealm against GF v3 and MySQL

Any suggestion?

Thanks again,
Jose


From: John Yeary ([email]address-removed[/email])
Sent: Tuesday, June 08, 2010 4:03 PM
To: nbj2ee ([email]address-removed[/email])
Subject: [nbj2ee] Re: Map<String, ?>




The implication is that you want to use generics. If you use Map() it is expecting Map(Object x, Object y) by default. In your case you are using Map<String ,y>(), you need to tell the compiler what y is. If you use one generic (String), you must tell the compiler what the second element is going to be, even if it is an Object. Try Map<String, Object>().

On Tue, Jun 8, 2010 at 6:29 AM, Jose Alvarez de Lara <address-removed ([email]address-removed[/email])> wrote:
Quote:
Hi,

What does Map<String, ?> mean?

I need to do,

Map<String, ?> options; // for an already instantiated Map
options.put("someString", someObject)

but the compiler does not let me.

Any suggestion about how does it work will be appreciated!!!

Regards,
Jose




--
John Yeary
--
http://javaevangelist.blogspot.com

"Far better it is to dare mighty things, to win glorious triumphs, even though checkered by failure, than to take rank with those poor spirits who neither enjoy much nor suffer much, because they live in the grey twilight that knows not victory nor defeat."
-- Theodore Roosevelt




--
John Yeary
--
http://javaevangelist.blogspot.com

"Far better it is to dare mighty things, to win glorious triumphs, even though checkered by failure, than to take rank with those poor spirits who neither enjoy much nor suffer much, because they live in the grey twilight that knows not victory nor defeat."
-- Theodore Roosevelt
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo