Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Craig Daniels   on Dec 01 In Java Category.

  
Question Answered By: Omar Walker   on Dec 01

As you have probably figured out the answer is no.
But you can force the client of your class  to not
change the underlying object that you return. For
example :

class ConstTest_C{
private String s;

public String getString()
{
if ( this.s == null )
return null;
else
return this.s.clone();
}

public void setString( String s ) { this.s = s; }
}

The user of your class can do anything they want with
the String that is returned by getString(), but it
will not change the class's String object.

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on returning const Or get search suggestion and latest updates.


Tagged: