472,960 Members | 2,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 software developers and data experts.

Superclass/subclass as Map element problem

Hi all,

I am trying to declare a Map object with an abstract superclass (TableFields_v2) object as follows:-
Expand|Select|Wrap|Line Numbers
  1. private Map<Integer, TableFields_v2> elementList;
When I come to create the object element for the Map I want to be able to use a subclass of the superclass for the object; for example:-

Expand|Select|Wrap|Line Numbers
  1. this.elementList = new HashMap<Integer, TableFields_v2_Year>();
Where TableFields_v2_Year is a subclass of TableFields_v2

However, Java won't let me do it this way! Can anyone help, or offer a suggestion?


Regards, Mark
Sep 16 '07 #1
2 2328
r035198x
13,262 8TB
Hi all,

I am trying to declare a Map object with an abstract superclass (TableFields_v2) object as follows:-
Expand|Select|Wrap|Line Numbers
  1. private Map<Integer, TableFields_v2> elementList;
When I come to create the object element for the Map I want to be able to use a subclass of the superclass for the object; for example:-

Expand|Select|Wrap|Line Numbers
  1. this.elementList = new HashMap<Integer, TableFields_v2_Year>();
Where TableFields_v2_Year is a subclass of TableFields_v2

However, Java won't let me do it this way! Can anyone help, or offer a suggestion?


Regards, Mark
Expand|Select|Wrap|Line Numbers
  1. Map<Integer, ? extends MyClass> myMap;
Map where an Integer is mapped to an object whose class extends MyClass.
Sep 17 '07 #2
Expand|Select|Wrap|Line Numbers
  1. Map<Integer, ? extends MyClass> myMap;
Map where an Integer is mapped to an object whose class extends MyClass.

r035198x,

Works perfect.

Many thanks for this, Mark
Sep 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Reid Priedhorsky | last post by:
Dear group, I'd have a class defined in one module, which descends from another class defined in a different module. I'd like the superclass to be able to access objects defined in the first...
3
by: chriss | last post by:
Hi, environment: Python 2.4, GNU/Linux, kernel 2.6.12.2 having subclassed 'Exception' I'm trying to call the initialiser __init__(...) of the superclass Exception with 'super(..).__init__(..)'...
2
by: stephane | last post by:
Hi all, What I am trying to achieve is an 'inherits' method similar to Douglas Crockford's (http://www.crockford.com/javascript/inheritance.html) but that can enable access to the superclass'...
4
by: ingoweiss | last post by:
Hi, I am having trouble passing parameters of a Javascript subclass constructor through to it's superclass constructor. I am trying all sorts of things, including the below, but nothing...
1
by: shivapadma | last post by:
1..In java we can refer superclass constructor by super()keyword,but Where as in c++ how can we refer to that???. In java the following code is used for referring superclass...
6
by: bill226 | last post by:
I have to get the subclass to use the superclass constructor, heres my code: public class Student { // instance variables private String name; private int pin; private...
14
by: Marko | last post by:
I have abstract superclass named Element, and several subclasses derived from it: And, Or, Nand, Nor... I have method which has to take 2 subclasses of element as its parameters types. Can't use ...
12
by: RajkiranPro | last post by:
well i have the following classes class Car { //some piece of code } class Benz : Car { //some piece of code
1
by: jimismint | last post by:
Hi guys, i'm stuck on this problem. only just recently started coding java using blue J. Can you guys help me. import java.util.*;...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.