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

  • Home
  • SEARCH
  • 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 118241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:27:48+00:00 2026-05-11T03:27:48+00:00

I hate the JavaBeans pattern with a passion that burns like the fire of

  • 0

I hate the JavaBeans pattern with a passion that burns like the fire of a thousand suns. Why?

  • Verbose. It’s 2009. I shouldn’t have to write 7 LOC for a property. If they have event listeners then hold on to your hat.
  • No type-safe references. There is no type-safe way to reference a property. The whole point of Java is that it is type safe, and its most popular pattern is not at all typesafe.

What I would like is something like:

class Customer {     public Property<String> name = new Property(); } 

I am a web developer mostly, so it needs JPA and Wicket support.

Help me off the javabean train!

  • 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. 2026-05-11T03:27:49+00:00Added an answer on May 11, 2026 at 3:27 am

    I think you’re pretty close with the declaration you have there (see below for a sketch). However, by using a non-beans approach, you’ll probably lose support provided by most tools that assume the JavaBeans protocol is in effect. Please be kind. The code below is off the top of my head…

    public class Property<T> {     public final String name;     T value;     private final PropertyChangeSupport support;      public static <T> Property<T> newInstance(String name, T value,                                                PropertyChangeSupport support) {         return new Property<T>(name, value, support);     }      public static <T> Property<T> newInstance(String name, T value) {         return newInstance(name, value, null);     }      public Property(String name, T value, PropertyChangeSupport support) {         this.name = name;         this.value = value;         this.support = support;     }      public T getValue() { return value; }      public void setValue(T value) {         T old = this.value;         this.value = value;         if(support != null)             support.firePropertyChange(name, old, this.value);     }      public String toString() { return value.toString(); } } 

    and then go ahead and use it:

    public class Customer {     private final PropertyChangeSupport support = new PropertyChangeSupport();      public final Property<String> name = Property.newInstance('name', '', support);     public final Property<Integer> age = Property.newInstance('age', 0, support);      ... declare add/remove listenener ... }   Customer c = new Customer(); c.name.setValue('Hyrum'); c.age.setValue(49); System.out.println('%s : %s', c.name, c.age); 

    So, now declaring a property is a single line of code and property change support is included. I called the methods setValue() and getValue() so it would still look like a bean to code like Rhino and stuff, but for succinctness, you could add just get() and set(). The rest is left as an exercise for the reader:

    • Properly handle serialization
    • Handle null value checking
    • Maybe add a specializations for atomic types if you care about autoboxing overhead.
    • ?? I’m sure there are more gotchas

    Also note that you can subclass (usually as an anonymous class) and override setValue() to provide additional parameter checking.

    I don’t think you can really get away from ‘String references’ since that’s pretty much what reflection’s all about.

    Sadly though, in this day and age, this is still kind of like programming in assembly… Groovy, C#, etc, etc may still be a better choice, if you have a choice.

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

Sidebar

Related Questions

I have a small to medium project that is in C++/CLI. I really hate
I hate to have to ask, but I'm pretty stuck here. I need to
For example, I hate typing things like: $x = mysql_escape_string(stripslashes($_GET['x'])); Is there a way
I hate to introduce Unit-tests into a legacy code base, but I have to.
I hate giving out my code like this but I'm getting some errors about
I am starting to love jQuery but as PHP developer I hate using that
I hate case sensitivity in databases, but I'm developing for a client who uses
I hate Physics, but I love software development. When I go back to school
I really hate sometimes how IDictionary<TKey, TValue> [key] will throw an exception if the
There's been a cluster of Perl-hate on Stack Overflow lately, so I thought I'd

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.