[program-l] Re: Java - alias for generic type

  • From: Roger Woolgrove <rawoolgrove@xxxxxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Thu, 27 Jun 2019 12:28:01 +0100

Hi

I think it is but you might want to include an overwritten version of get(k) and other methods which checks the returned object instance and return a hash map of its own containing key which is a string of the class name of the object and the value as the object instance. Then you will be able to parse as required.

I haven't tried this but expect that there might be rules about this kind of thing. The class name should be retrieved inside your new class otherwise you will put a lot of extra processor time into parsing.
HTH

roger


On 27/06/2019 11:06, Lubos Pintes wrote:

Hello Java geeks,

I have a question about some kind of type aliasing in Java. I am playing with manual JSON parsing, only exercise. I am representing JSON as Map<String, Object>. I am using LinkedHashMap. I would like to define a class JSON that would somehow extend LinkedHashMap<String, Object>, so that I could write:

JSON json=new JSON();

json.put("x", 1);

Is it possible?

Thanks


** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: