Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-18-2007, 07:15 PM
Member
 
Join Date: Jul 2007
Posts: 8
snooze-g is on a distinguished road
Function declaration problem.
Hi all.
Imagine that wi have an interface like this
Code:
public Interface MyInterface { public void function1(Object a); }
how i must write my function definition to be sure that the function1 doesn't change my Object a during his work.

Best Snooze-G.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-18-2007, 08:36 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
What about this? Is it working?

Code:
public Interface MyInterface { public void function1(final Object a); }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-18-2007, 10:51 PM
Member
 
Join Date: Jul 2007
Posts: 8
snooze-g is on a distinguished road
No, of course it doesn't work, because Java work in referance system, for Java it mean that the referance of "Object a" can't be changed, not content but the referance.
For example.
Code:
public void function1(final Object a) { 1. a=new Object(); 2. a.text="new text"; }
It wil get a compiler time error on line 1, but not on line 2.

Best Snooze-G.
Thanks.

Last edited by snooze-g : 07-18-2007 at 10:55 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-18-2007, 11:15 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
That is right. Then you will design your Object such a way that method can not change its content.

For example, define an interface which will only have the method you want to be called from this method and send this method the interface instead of actual object.

Of course the method can try casting the object to its actual type, but if you really want to protect that object then only way is to not sending that object obviously
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaration asifahmed New To Java 1 04-05-2008 07:38 AM
multiple declaration of a variable eva New To Java 2 01-28-2008 11:17 AM
Array size declaration JT4NK3D New To Java 3 01-19-2008 12:37 AM
JSP Declaration Directive Java Tip Java Tips 0 12-10-2007 07:42 PM
problem with Vectors and getTotal() function java_fun2007 New To Java 2 11-23-2007 03:55 PM


All times are GMT +3. The time now is 04:23 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org