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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:05:50+00:00 2026-06-14T20:05:50+00:00

Per Effective Java by Joshua Blotch: There is no way to extend an instantiable

  • 0

Per Effective Java by Joshua Blotch:

There is no way to extend an instantiable class with a new value
component while preserving the compareTo contract, unless you are
willing to forgo the benefits of object-oriented abstraction

Can you please explain the above with examples and the challenges? Can you also explain what Joshua means by “Value Component” and what other types of components are available.

This frees you to implement whatever compareTo method you like on the
second class, while allowing its client to view an instance of the
second class as an instance of the first class when needed.

Can you also explain what Joshua means by second class as an instance of the first class?

  • 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-06-14T20:05:51+00:00Added an answer on June 14, 2026 at 8:05 pm

    Can you please explain the above with examples and the challenges?

    Sure. Consider two classes like this – I’ve left out all the getters, setters etc, but hopefully you get the drift:

    class NamedThing {
        String name;
    }
    
    class Person extends NamedThing {
        Date dateOfBirth;
    }
    

    Ignore whether this is a good example of inheritance – it’s a simple one.

    It would be natural for NamedThing to implement a comparison based on name, in alphabetical order.

    It would also be natural for Person to implement a comparison which first compares the name (so stays consistent in that respect) but then also checks for one date of birth being earlier than another.

    Now imagine this:

    NamedThing person1 = new Person("Jon", date1);
    NamedThing person2 = new Person("Jon", date2);
    NamedThing thing = new NamedThing("Jon");
    
    int comparison1 = person1.compareTo(thing);
    int comparison2 = person2.compareTo(thing);
    int comparison3 = person1.compareTo(person2);
    int comparison4 = thing.compareTo(person1);
    

    What would you want all these results to be? If Person.compareTo was smart enough to only apply its date processing to instances of Person, then you might expect comparison1 and comparison2 to be 0, but comparison3 to be non-zero.

    Presumably comparison4 would have to be 0, as it’s using NamedThing.compareTo, which only compares names.

    Fundamentally, there’s a problem trying to compare instances of different types. It ends up being cleaner to have an external definition of a comparison, which defines what comparison it will use. You could thus have a Comparator<Person> which only accepted Person references and used both name and date, and a Comparator<NamedThing> which only compared by name. The behaviour would have symmetry and clarity.

    Can you also explain what Joshua means by second class as an instance of the first class?

    You’ve taken it out of context. It’s: “view an instance of the second class as an instance of the first class” – e.g.

    // First class = Animal
    // Second class = Zebra
    Animal person = new Zebra();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Joshua Bloch's Effective Java, Item 51 is not about depending on the thread scheduler
Is there any easy and effective way to track user activities from my iPhone
Per a client's request I have written a communication class that inherits from webclient.
What is an effective way of dealing with EWS throttling policies? I'm attempting to
I come from a background where I normally create one file per class. I
My end goal is to make node.js more cost effective per each server instance.
I've been reading Effective Java and decided to try to put some of what
I am interested in knowing what is the effective way of loadAll method implementation
Our software company receives literally hundreds of support requests per day and there's a
Is using an integer flag and bitwise operations an effective way of reducing the

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.