Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3606336
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:14:08+00:00 2026-05-18T21:14:08+00:00

class MyThing { protected HashMap<String,Object> fields; protected MyThing(HashMap<String,Object> newFields){ fields.putAll(newFields); } protected Object get(String

  • 0
class MyThing {
    protected HashMap<String,Object> fields;

    protected MyThing(HashMap<String,Object> newFields){
        fields.putAll(newFields);
    }

    protected Object get(String key){
        return fields.get(key);
    }
}

Now a little background. I am using this class as a super class to a bunch of different classes which represent objects from an XML file. This is basically an implementation of an API wrapper and I am using this as an adapter between the parsed XML from an API and a database. Casting is delegated to the caller of the get method. If the subclasses need to do something when they are created or when they return a variable, they just call super and then manipulate what gets returned afterwards. eg.:

class Event extends MyThing {       
    public Event(HashMap<String,Object> newFields){
        super(newFields);

        // Removes anything after an @ symbol in returned data
        Pattern p = Pattern.compile("\\@.*$");
        Matcher m = p.matcher((String)fields.get("id"));
        boolean result = m.find();

        if (result)
            fields.put("id", m.replaceFirst(""));
        }
    }

    public Object get(String key){
        Object obj = super(key);

        if (key.equals("name")){
            return "Mr./Mrs. " + ((String)obj);
        }
    }
}

The reason I feel like I should do this is so I don’t have to write getId, getName, getWhatever methods for every single subclass just because they have different attributes. It would save time and it is pretty self explanatory.

Now this is obviously “unJavalike” and more like a ducktyped language way of doing things, but is there a logical reason why I should absolutely not be doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:14:09+00:00Added an answer on May 18, 2026 at 9:14 pm
    1. Obviously, it’s not type safe.
    2. Future maintainers won’t know what the types are supposed to be and will get generally confused as to why you’re not using POJOs.
    3. Instead of constant time, space complexity and performance you have the characteristics of a HashMap.
    4. It become very difficult to write non-trivial getters/setters in future.
    5. Most data binding systems are designed to work with POJOs/Beans (JAXB, JPA, Jackson, etc).

    I’m sure there are more, but this will do. Try using some proper OXM libraries and you’ll be much better off.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.