Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Custom class extends HashMap - error: "Does not take parameters"

809141Oct 28 2010 — edited Nov 1 2010
Hello all! This is my first forum post, and I chose this board because it seems to be the most active. I am fairly new to Java, but I'm already pretty deep into the language.

I have a custom class declared as follows:

public class DBFRecord extends HashMap {

// methods here, but no constructor

}

The idea was to get a custom HashMap class with a method for retrieving specifically typed values. My understanding is that, since I didn't include a constructor for the class, it defaults to the parent constructor, which is, of course, HashMap(). Where I ran into trouble was when I tried to fix a compiler warning that complained about an "unchecked put." I read somewhere that this can be fixed by specifying the data type of the map at instantiation. So, I tried this:

DBFRecord<String, Object> record = new DBFRecord<String, Object>();

and the compiler, instead of being pleased, slapped me with an error:

"type com.svcon.jdbf.DBFRecord does not take parameters"

So, just to prove the point, I tried:

HashMap<String, Object> record = new HashMap<String, Object>();

and it worked perfectly (though of course it messed up the rest of the program royally.)

My question, then, is this: How does one declare a child class (if that's the right term) such that it takes the same parameters as the parent?
This post has been answered by EJP on Oct 28 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 29 2010
Added on Oct 28 2010
24 comments
1,316 views