tag:blogger.com,1999:blog-3718956085911858962.post3687932475964650563..comments2023-12-27T14:48:02.113+05:30Comments on Electric Sheep Blog: Why isn't Java's Object class abstract?Anonymoushttp://www.blogger.com/profile/11938300811286150164noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-3718956085911858962.post-76823377017723608112010-07-06T19:58:38.657+05:302010-07-06T19:58:38.657+05:30I don't think it's a question of defining ...I don't think it's a question of defining methods at all. The real question is, can you come up with a case where you want to instantiate Object and Ajit has done that in his comment 3 years ago.Troffhttps://www.blogger.com/profile/08052594109965873482noreply@blogger.comtag:blogger.com,1999:blog-3718956085911858962.post-22754263248284777702008-09-02T12:57:00.000+05:302008-09-02T12:57:00.000+05:30Not only the Object class should have been abstrac...Not only the Object class should have been abstract, but even there should be rule that the compiler should not allow abstract sub class for a concrete class. This is in accordance to the basic inheritance philosophy, that a sub class can only add to the functionality provided by the super class. In the current scenario the we stop instantiation of a sub class (which is abstract) which is allowed in the super-class.Pravin Jainhttps://www.blogger.com/profile/05715250605774780545noreply@blogger.comtag:blogger.com,1999:blog-3718956085911858962.post-89142052818726509412007-10-23T18:28:00.000+05:302007-10-23T18:28:00.000+05:30And I forgott to mention, haveing one common base ...And I forgott to mention, haveing one common base let's you have heterogeonus objects in one and same collection. Now that Java got generics, it is probably less obvious, but when lang was invented it didn't have generics. Furthermore, generics are actually resting on exactly that design of having one common Object as mother of all other classes .... So Object has otehr reasons to be concrete class but only having methods in Object cthat an be accepted as default, as Stacy perceives it. That is yet another practical reason of having common base for all objects.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3718956085911858962.post-58728934031254053992007-10-23T18:20:00.000+05:302007-10-23T18:20:00.000+05:30I have seen so many explanations and disscussions ...I have seen so many explanations and disscussions of java Object, it's need, why is it not interface or maybe abstract, or not only implicit, in sense that compiler should "know" about it methods and implicitly cretate them when needed.<BR/><BR/>There are so many academic explanations, yet nobody has ever thought of something simple, like beeing practical. Not everything has to have deep theoretical meaning.<BR/><BR/>Imagine that Object was interface or abstract class. In that case you will have to implement several methods in every class you ever wrote!!! Sounds practical? I guess it would never become THE #1 teaching object oriented lang in the world in THAT case. Just image how many classes you wrote that never called base methods.<BR/><BR/>Last option is why it is not implicit, like "class" field for example. I guess answer is still simply practical: it would unneccessary complicate compiler and language definition. It is probably not impossible to make a compiler that recognizes if you call number of "special" methods that belongs to Object class. Further it would need to now if those classes are user defined to exchange "implicit" ones for users. But then one has to change language deff as well. To me it seems more practical to make one exception (of having single inhertiance) for Object class and let language mechanism deal with other issues, then to implement Object and it's methods "implicitly" in compiler, rather as real class.<BR/><BR/>So my answer is simply, Object class is not abstract or interface for practical reasons, both for programmers, and for compiler makers.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3718956085911858962.post-24342111395422804802007-09-13T06:02:00.000+05:302007-09-13T06:02:00.000+05:30Just because the methods in Object can be accepted...Just because the methods in Object can be accepted as default should not exclude making Object abstract simply because it's too vague. When I want to instantiate an object I always have a particular purpose in mind, Object should be abstract not to force implementation of equals / hashcode etc, but to <B>name</B> that purpose.Stacy Curlhttps://www.blogger.com/profile/01599842149600715942noreply@blogger.comtag:blogger.com,1999:blog-3718956085911858962.post-8724310333456148022007-09-12T13:39:00.000+05:302007-09-12T13:39:00.000+05:30Hi Sidu, A very enlightening post on the design i...Hi Sidu,<BR/><BR/> A very enlightening post on the design intentions behind the Object Class in the Java.<BR/><BR/>Keep it up.<BR/><BR/>Rameshkoundinyahttps://www.blogger.com/profile/13114395598300524871noreply@blogger.comtag:blogger.com,1999:blog-3718956085911858962.post-70700949066519941682007-09-12T10:09:00.000+05:302007-09-12T10:09:00.000+05:30Hey Sidu, I like the way you covered differen...Hey Sidu, <BR/> <BR/> I like the way you covered different languages to explain your answer. I totally agree with you on your thoughts on this question. However here are my thoughts on the same question.<BR/><BR/> Firstly the object class is a collection of final methods, native methods and others methods which can be overriden like toString() , hashcode() , equals() etc. The Object class has default implementation for all methods which means the class is a complete class and hence no need for abstraction. <BR/><BR/> Secondly sometimes you need a lightweight object for the purpose of locking when it comes to threads. In Java the lightweight object is the Object class and you can perform synchronization using the object class.<BR/><BR/> What do you think Sidu?Ajit Balanhttps://www.blogger.com/profile/12744636895930257724noreply@blogger.comtag:blogger.com,1999:blog-3718956085911858962.post-39854284081277330102007-09-12T06:11:00.000+05:302007-09-12T06:11:00.000+05:30A very good question and even better explanation. ...A very good question and even better explanation. Well done!!braincells2pixels.nethttps://www.blogger.com/profile/02342896413820654978noreply@blogger.com