Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Adam Gerber
/
labJava
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a6c598f2
authored
May 12, 2015
by
Joe Student
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some minor mods
parent
9db188b4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
4 deletions
src/lec07/glab/casting/CastObjectsDriver.java
src/lec07/glab/casting/CastPrimitivesDriver.java
src/lec07/glab/recursion/RecursionDriver.java
src/lec07/glab/casting/CastObjectsDriver.java
View file @
a6c598f2
...
@@ -39,7 +39,7 @@ public class CastObjectsDriver {
...
@@ -39,7 +39,7 @@ public class CastObjectsDriver {
//With reflection, we can see that we are NOT changing the object's type, it's still a Double, only now it's
//With reflection, we can see that we are NOT changing the object's type, it's still a Double, only now it's
//being stored in a superlcass reference which restricts the of methods we can call on the reference
//being stored in a superlcass reference which restricts the of methods we can call on the reference
//This is an automatic promotion, so the cast here is redundant
//This is an automatic promotion, so the cast here is redundant
Number
numMe
=
(
Number
)
dubMe
;
Number
numMe
=
dubMe
;
System
.
out
.
println
(
"A Number reference pointing to same Double object:"
);
System
.
out
.
println
(
"A Number reference pointing to same Double object:"
);
System
.
out
.
println
(
numMe
.
getClass
().
toString
());
System
.
out
.
println
(
numMe
.
getClass
().
toString
());
//one of the methods we can call from the Number reference
//one of the methods we can call from the Number reference
...
@@ -60,7 +60,7 @@ public class CastObjectsDriver {
...
@@ -60,7 +60,7 @@ public class CastObjectsDriver {
System
.
out
.
println
(
"numMe and dubMe both point to the same object in memory space: "
+
(
numMe
==
dubMe
));
System
.
out
.
println
(
"numMe and dubMe both point to the same object in memory space: "
+
(
numMe
==
dubMe
));
System
.
out
.
println
(
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
);
System
.
out
.
println
(
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
);
System
.
out
.
println
(
Double
.
valueOf
((
Double
)
comMe
));
//Now let's cast this to an Object
//Now let's cast this to an Object
//This is an automatic promotion, so the cast here is redundant
//This is an automatic promotion, so the cast here is redundant
Object
objMe
=
(
Object
)
comMe
;
Object
objMe
=
(
Object
)
comMe
;
...
...
src/lec07/glab/casting/CastPrimitivesDriver.java
View file @
a6c598f2
...
@@ -28,7 +28,7 @@ public class CastPrimitivesDriver {
...
@@ -28,7 +28,7 @@ public class CastPrimitivesDriver {
//Let's promote this to an int which is a 32-bit signed integer ranging from -2^31 to 2^31 - 1
//Let's promote this to an int which is a 32-bit signed integer ranging from -2^31 to 2^31 - 1
int
nMe
=
(
int
)
sMe
;
int
nMe
=
sMe
;
//no problem, we don't really need all the precision, but memory is cheap, and the value stays the same.
//no problem, we don't really need all the precision, but memory is cheap, and the value stays the same.
//when we copy the bits, we just put those bits into an 32-bit int like so ->
//when we copy the bits, we just put those bits into an 32-bit int like so ->
//upcasting is automatic (no cast required) and looses no precision
//upcasting is automatic (no cast required) and looses no precision
...
...
src/lec07/glab/recursion/RecursionDriver.java
View file @
a6c598f2
...
@@ -7,7 +7,7 @@ public class RecursionDriver {
...
@@ -7,7 +7,7 @@ public class RecursionDriver {
*/
*/
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
myFactorialRec
(
5
));
System
.
out
.
println
(
myFactorialRec
(
12
));
System
.
out
.
println
(
myFactorialIter
(
5
));
System
.
out
.
println
(
myFactorialIter
(
5
));
testIsPalindrome
(
"A man, a plan, a canal, Panama!"
);
testIsPalindrome
(
"A man, a plan, a canal, Panama!"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment