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 7439201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:40:19+00:00 2026-05-29T10:40:19+00:00

Say I have a class, User: public class User { private String name; private

  • 0

Say I have a class, User:

public class User {
    private String name;
    private Integer age;
    private Double cash;

    // Getters and setters...
}

Some magic system spits out data for all Users and my system picks it up. Some employees need to report on this data, but some of it is known to be incorrect. Since the source system is magic, nobody can mess with the user data in it, so they need to use my system to update this data so that it is correct in the report. Thus, I want to make a class that’s something like the following:

public class UserUpdate {
    private UserPropertyEnum property;
    private Something newValue;
    private Date dateAdded;

    // Getters and setters...
}

So the problem lies in that I don’t know the type of the field I’m changing. I suppose I could make newValue of type Object, and cast based on the value of the property enum…

Anyway, is there a good design pattern that solves this? And if there is, how is it implemented in the data layer (I’m using a relational database)?

(Please refrain from “you’re unchangeable magic system is stupid… don’t store data that’s known to be incorrect” posts as I’m aware of this and am completely powerless to do anything about it.)

Thanks!

  • 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-29T10:40:20+00:00Added an answer on May 29, 2026 at 10:40 am

    In C#, I would use generics. You can do something like:

    public class UserUpdate<T> {
        private UserPropertyEnum property;
        private T newValue;
        private Date dateAdded;
    
        // Getters and setters...
    }
    

    And then create an update, say, for Salary using:

    UserUpdate<Int32> salaryUpdate = new UserUpdate<Int32>();
    salaryUpdate.newValue = 50000; //This will be an int, no need to cast
    

    I’m assuming your updates are hard coded into some sort of mechanism that “patches” your magic data, so the types of each update would be known. I believe generics work the same way in Java, but you’ll have to confirm.

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

Sidebar

Related Questions

Let's say I have following POJO's using Hibernate. public class User { private String
Say I have this class: @Entity @Table(name=PICTURE) public class Picture{ private String category1, category2;
I have a user defined class, say import java.util.Calendar; public class Employee{ private String
Lets say I have some view models set up as follows: public class User
so lets say I have some model class: public class MyRequestParams { private Long
Lets say we have some basic AR model. class User < ActiveRecord::Base attr_accessible :firstname,
Let's say I create a class with a property: public class User { private
Say I have a User Control in ASP.NET that contains a button: public class
Let's say I have two objects: User and Race. class User attr_accessor :first_name attr_accessor
Say I have class A with class A { final String foo() { //

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.