aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enthuware Map question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Enthuware Map question" Watch "Enthuware Map question" New topic
Author

Enthuware Map question

John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 165
Hi,

One question in Enthuware is:

Which of these statements concerning maps are true?

One option is:

It is permissible for a map to contain itself as a key.

In the review it says this option is wrong 'But it can contain itself as a value'.
I don't really know what that means. Can anybody explain?

Thanks,

John
Riza Aktunc
Greenhorn

Joined: Sep 07, 2011
Posts: 24
A map has two attributes - key and value.
Judging by what you have posted; a map can contain itself as a value but not a key.

String x="";
HashMap hm=new HashMap();
hm.put(hm,x); //not ok
hm.put(x,hm); //ok

But, when I try it, compiler does not complain! In runtime hm.put(hm,x); gives StackOverFlowError!


OCPJP - 93%
John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 165
So the StackOverFlowError occurs because the map contains itself which contains itself contains itself ...?
Why does this not occur when adding the map as a value?

Thanks,

John
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Enthuware Map question
 
Similar Threads
Adding different objects to same in HashMap?
Enthuware com.enthuware.ets.scwcd.v5.2.70
jsf selectitems problem
Collection
Enthuware (SCWCD) - issues