Raised This Month: $ Target: $400
 0% 

Java Scripting


Post New Thread Reply   
 
Thread Tools Display Modes
Sean D
Junior Member
Join Date: Apr 2006
Old 03-03-2009 , 00:12   Re: Java Scripting
Reply With Quote #11

the alternative to what's already been said is to create your own wrapper class, which takes like 5 seconds, but it's a real pain that java's Integer class (and other numeric types) are immutable
Sean D is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-03-2009 , 07:28   Re: Java Scripting
Reply With Quote #12

Quote:
Originally Posted by joaquimandrade View Post
You are learning Java or do you need that for a specific purpose?
Well, both.
I'm taking a Java class at school, but this isn't an assignment.
It's a program that I'm writing for myself since I always finish the work early.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-03-2009 , 08:04   Re: Java Scripting
Reply With Quote #13

Quote:
Originally Posted by Exolent[jNr] View Post
Well, both.
I'm taking a Java class at school, but this isn't an assignment.
It's a program that I'm writing for myself since I always finish the work early.
Ok so let me say that you normally won't need that. You will work with non static classes and you will pass them to each other or operating directly on them. As an example:

Code:
class Point
{
    private int x;
    private int y;
    
    Point(int x,int y)
    {
        this.x = x;
        this.y = y;
    }
    
    public void setX(int x)
    {
        this.x = x;
    }
    public int getX()
    {
        return this.x;
    }
    
    public void showMe()
    {
        System.out.println("My coordinates are [" + this.x + "][" + this.y + "]");
    }
    
}

public class Main 
{
    public static void main(String[] args) 
    {
        Point myPoint = new Point(1,3);
        
        myPoint.showMe();
        
        myPoint.setX(5);
        
        myPoint.showMe();
    }
}
joaquimandrade is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 03-03-2009 , 08:28   Re: Java Scripting
Reply With Quote #14

Try using the Integer class, I can't remember if that gets passed by ref or not.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-03-2009 , 08:40   Re: Java Scripting
Reply With Quote #15

Quote:
Originally Posted by YamiKaitou View Post
Try using the Integer class, I can't remember if that gets passed by ref or not.
It won't work
joaquimandrade is offline
Jheshka
Senior Member
Join Date: Dec 2005
Old 03-03-2009 , 09:03   Re: Java Scripting
Reply With Quote #16

Which editor are you using?
__________________
James
Jheshka is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 03-03-2009 , 09:18   Re: Java Scripting
Reply With Quote #17

Quote:
Originally Posted by joaquimandrade View Post
It won't work
Can you say more than "won't work"? Integer is part of the Object class from what I can remember. It has been a about a 1.5 years since I messed with Java and almost 3 since I messed with the Integer class. I might just test it unless you can tell me. Integer and int are seperate classes, so don't mix them together if that is what you are doing.

Nvm, tested it and it does seem that it does not pass it as a Object
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 03-03-2009 at 09:41.
YamiKaitou is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-03-2009 , 09:45   Re: Java Scripting
Reply With Quote #18

Quote:
Originally Posted by YamiKaitou View Post
Can you say more than "won't work"? Integer is part of the Object class from what I can remember. It has been a about a 1.5 years since I messed with Java and almost 3 since I messed with the Integer class. I might just test it unless you can tell me. Integer and int are seperate classes, so don't mix them together if that is what you are doing.

Nvm, tested it and it does seem that it does not pass it as a Object

Yes, i said that it wouldn't work cause i've tested it. An Integer is a descendent from the class Object but still is not passed by reference. I'm searching for an explanation

Edit:

http://www.yoda.arachsys.com/java/passing.html


The language where objects are passed by reference is C#, not Java.

Last edited by joaquimandrade; 03-03-2009 at 09:59.
joaquimandrade is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 03-03-2009 , 10:06   Re: Java Scripting
Reply With Quote #19

Quote:
Originally Posted by joaquimandrade View Post
Yes, i said that it wouldn't work cause i've tested it. An Integer is a descendent from the class Object but still is not passed by reference. I'm searching for an explanation
It was more of doubting myself than doubting you.

Quote:
Edit:

http://www.yoda.arachsys.com/java/passing.html


The language where objects are passed by reference is C#, not Java.
Yeah, Java will only pass by reference if the value of the variable is a reference location, I am starting to remember this now.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-03-2009 , 10:13   Re: Java Scripting
Reply With Quote #20

Quote:
Originally Posted by YamiKaitou View Post
It was more of doubting myself than doubting you.


Yeah, Java will only pass by reference if the value of the variable is a reference location, I am starting to remember this now.
Yes, no problem.


Quote:
Originally Posted by Jheshka View Post
Which editor are you using?
In my course we use Eclipse.
joaquimandrade is offline
Reply



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode