Forums Register Login

a simple question

+Pie Number of slices to send: Send
i want to make a class same as String(immutable, which can be initialized like
String="abc"; // normally we do String a = new String("abc");
Kindly help me out
+Pie Number of slices to send: Send
What do you have so far, and what are you struggling with?
+Pie Number of slices to send: Send
If you mean that you want to be able to write a kind of String-like class which you could initialize by assigning a string literal, like this:

MyOwnStringlikeClass str = "Hello";

Then that's not possible in Java. The compiler does some special things for class String which do not work with classes that you write yourself.
+Pie Number of slices to send: Send
As for making objects immutable, just don't create any methods that can modify your data, and keep the data private. If you make it protected or use default access, other classes are still able to change the object.
That new kid is a freak. Show him this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 462 times.
Similar Threads
Permutations - upper case and lower case
Stack Overflow
question regarding strings
Struggeling with regexp
String Immutable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:12:31.