5 Replies - 347 Views - Last Post: 05 July 2017 - 09:36 AM

#1 ccdan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 107
  • Joined: 09-December 12

Yet another example of idiotic and wrong java terminology

Posted 04 July 2017 - 01:35 PM

From the JLS:

Quote

8.2. Class Members

The members of a class type are all of the following:

Members inherited from its direct superclass (§8.1.4), except in class Object, which has no direct superclass

Members inherited from any direct superinterfaces (§8.1.5)

Members declared in the body of the class (§8.1.6)

Members of a class that are declared private are not inherited by subclasses of that class.


Oh, really? Really, really, really? Then how the heck are the private values accessed by subclasses?

Of course they're inherited, but for some very mysterious reason, the folks taking care of Java, seem to have their own very original ideas about what inheritance is, what pass by value is and so on.

What pisses me off, is stuff like the this(topics on verious sites, articles and so on):
https://stackoverflo...-private-fields
https://community.or...tart=0&tstart=0

Lots and lots of idiotic comments... many people seem to miss some very simple concepts: a class is just a blueprint; unless there's some static stuff in there, or there's an instance of the said class, that class doesn't exist on its own... if a another class extends it, it(the subclass) simply inherits the data of the original class... and an instance of the subclass will have its own members, including those "private" members from the original class... there's no other way around it!

The fact that private members cannot be accessed directly, doesn't make them "not inherited"

And I thought that OOP concepts were language-independent. But hey... what do I know?

This post has been edited by ccdan: 04 July 2017 - 01:37 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Yet another example of idiotic and wrong java terminology

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13491
  • View blog
  • Posts: 53,888
  • Joined: 12-June 08

Re: Yet another example of idiotic and wrong java terminology

Posted 04 July 2017 - 03:16 PM

So for the basic usage they are inherited, but difficult to access hence why 'protected' exists, right?
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10686
  • View blog
  • Posts: 18,302
  • Joined: 19-March 11

Re: Yet another example of idiotic and wrong java terminology

Posted 04 July 2017 - 03:30 PM

Quote

But hey... what do I know?


I don't know... what do you know? I mean, clearly you have very strong opinions about language design - is there an example of a language that gets it right, in your book?

To me, it seems that maybe it would be more productive to start out with a question like "why is Java designed this way, instead of this other way?" than to come out of the gate with stuff like "idiotic". Or even better, to give an example of how this design hampers you in writing useful Java code, and how you'd prefer it to work. That would seem to me a path more likely to lead to some enlightenment.

I mean, it's not news that Java has some design opportunities. People have been complaining about it for years - just about since it was first released, in fact. And the access modifiers have always been a popular target for complaints - notice that many languages seem to get along fine without any ability to restrict access to an object's members. And yet, some very smart people designed it that way, and some other smart people have chosen Java over many other options for years. So clearly there's something to talk about here, from both ends. Why not start out with that, instead of leading with your flamethrower?
Was This Post Helpful? 0
  • +
  • -

#4 ccdan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 107
  • Joined: 09-December 12

Re: Yet another example of idiotic and wrong java terminology

Posted 05 July 2017 - 02:35 AM

View Postmodi123_1, on 05 July 2017 - 01:16 AM, said:

So for the basic usage they are inherited, but difficult to access hence why 'protected' exists, right?

Yes, but that's not what I'm talking about. I'm strictly referring to the notion of inheriting private members, which, in java official documentation, is claimed to be impossible. But which is technically false.

View Postjon.kiparsky, on 05 July 2017 - 01:30 AM, said:

I don't know... what do you know? I mean, clearly you have very strong opinions about language design - is there an example of a language that gets it right, in your book?

To me, it seems that maybe it would be more productive to start out with a question like "why is Java designed this way, instead of this other way?" than to come out of the gate with stuff like "idiotic".

I can't remember to have said anything specifically about language design. Java is pretty well designed. That's not the problem.
The problem is the terminology they're using in the official documentation - besides causing a lot of unnecessary confusion, it's technically inaccurate.

Why should they say that "Members of a class that are declared private are not inherited by subclasses of that class." ????

How come they aren't inherited? Just because they're not directly accessible?

Let's make an experiment!

Suppose we have the following classes:

class SomeClass {
	private int someprivatenumber = 5;

	public void show() {
		System.out.println(someprivatenumber);
	}
}


and AnotherClass which has its own x variable

class AnotherClass extends SomeClass {
	int x = 4;
	
	void showx() {
		System.out.println(x);
	}
}


and then in main we create an instance of AnotherClass and use the inherited public method.

AnotherClass d = new AnotherClass();
		
		while (true) d.show();


(the loop is for creating a heap dump)

Question: is someprivatenumber specified in the superclass SomeClass inherited by AnotherClass? The Java Language Specification says no.

This is what the VisualVM tells us:

Posted Image

This post has been edited by ccdan: 05 July 2017 - 02:45 AM

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13491
  • View blog
  • Posts: 53,888
  • Joined: 12-June 08

Re: Yet another example of idiotic and wrong java terminology

Posted 05 July 2017 - 07:04 AM

Have you considered - politely - emailing/social media contacting any of the JLS folk to them make a change in the wording?

Quote

Java SE 8 Edition

James Gosling
Bill Joy
Guy Steele
Gilad Bracha
Alex Buckley
2015-02-13

Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10686
  • View blog
  • Posts: 18,302
  • Joined: 19-March 11

Re: Yet another example of idiotic and wrong java terminology

Posted 05 July 2017 - 09:36 AM

Quote

I can't remember to have said anything specifically about language design. Java is pretty well designed. That's not the problem.


In that case, I don't see what the problem is. As a user of the java language, what is the issue you're trying to resolve?
In what way does this affect you as a writer of java code?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1