• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it possible to change default implementation of java built in classes!  RSS feed

 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers!
I want to change the default implementation of some method which will be members of some built in class of java. Let's say length method of string class will return string insted of returning int. Now i find out the source of string class made the changes and compiles the same Now what should i do to reflect this changes to orignal code???

Thanx in Advance!
Sachin Dimble.


- India_Will_Become_SuperITPower(new Lets_Go_ForIt());
 
Thennam Pandian
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java refer the All Classes from ur JavaInstalledDir\JRE\LIB\rt.jar file.

if u want to do change any default class behaviour or add one more class to

default package.(i.e u need ur own library file)



for that u have to create ur own runtime .

u have to add the your owun class file into rt.jar file.


before doing that make the copy of standard rt.jar(sun's runtime..)

creating new rt.jar file by adding ur own class file .

after adding it you can replace the rt.jar file in


JavaInstalledDir\JRE\LIB .
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And expect many runtime errors unless you changed every class in your code and the libraries and any third party jars to expect a String back from length. This is not something I'd try!
 
Adam Richards
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Theoretically, it's possible, but if you find yourself wanting to do this, it's a sign of a poorly designed app.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want String.length() to return a String? I'm sure there is a reason that the designers of the API created this method the way it is. I strongly suggest you find a different way to solve the problem. Perhaps writing your own wrapper class would work. Modifying the API source seems very dangerous to me.

Layne
 
Martin Mathis
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you should just create your own class... one that is a wrapper around the String class, and add your method there.

Changing a method in the String class sounds like a terrible idea. I guess you could get away with adding a new method, but still...
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Martin Mathis:
Maybe you should just create your own class... one that is a wrapper around the String class, and add your method there.

Changing a method in the String class sounds like a terrible idea. I guess you could get away with adding a new method, but still...


Isn't that what I said? I guess great minds think alike.
 
Martin Mathis
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Layne Lund:


Isn't that what I said? I guess great minds think alike.


Haha. I don't know how I missed your reply Maybe its a Monday morning thing, hehe.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!