You haven't said WHY they'd do it.
|
What i'm teaching:
The basics on how to convert Strings into other things & convert classes or Objects into other classes.
1:
Strings to others:
We call three Strings:
We want the Strings to behave as other types.Code:private String i = "3"; private String d = "0.3"; private String b = "true";
So this is what we are going to do:
Thats calling a new integer named I and parsing a String (converting) into a integer.Code:private int I = Integer.parseInt(i);
The same style goes throughout:
Code:private double D = Double.parseDouble(d); private boolean B = Boolean.parseBool(b);2:
Classes / Objects to other Classes:
Okay this is very simple. To convert classes into other classes simply do this
Please note the classes must have SOME relation for this to work.Code:Class1 = (Class1)Class2;
You can also call Objects to store them as classes, this is also simple.
Simpley call an Object like so:
Then inside a method or while calling the Object set its value.Code:private Object obj;
Personally I like getters and setters but this way works just the same.
Thank you for reading, I will be posting more of these basic java tutorials and a few intermediate and advanced ones.Code:public void ChangeObj() { obj = Class1; } //Or private Object obj = Class1;
You haven't said WHY they'd do it.
Could be used in a range of ways, loading configuration files, etc.
EDIT:
And for Objects storing classes could be used for things such as, differencing between NPCs and humans but still using the same classes
This is called casting..Class1 = (Class1)Class2;
Good job
Casting, bro.
Put Float in there and indent.
gj.
Good job.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |