Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Jason Kilgrow

Ranch Hand
+ Follow
since May 21, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jason Kilgrow

I thought this was interesting...
Consider the following:

All of these compile. When I run TestIn, I get:
I'm driving my amphibious
I'm a Car
I'm a Boat
I'm an Amphibious
Which is what I would expect. Syntactically, this is all correct. But it really doesn't make sense logically. Where am I driving my Amphibious? On the road or on the lake? In other words, which interface's drive() method do I mean to implement in Amphibious? Car or Boat? Does it matter? Is there a way to specify which interface method I'm referring to in Amphibious?
added code tags - Pauline
[ May 25, 2002: Message edited by: Pauline McNamara ]
18 years ago

Originally posted by Michael Matola:
Right. A class can call super only on its own immediate superclass.
Think of it this way. All this business about calling superclass methods can be thought of as an implementation detail of a given class, which should be hidden from users. You as an external user of that class can only interact with that class or its instances through its public interface (constructors, methods, fields).


Ok. Thank you. That makes sense.


But is there something you're writing in which you think you need to do this sort of thing?[/QB]


Actually, no. It's purely academic. The question came up by trying to learn C#. There was a discussion in my book about the use of "virtual" and "overload" keywords. C# implements early binding by default and in our Truck...DodgeRam example, the Truck method would be called unless the Truck method was defined as vitrual (via the "vitrual" keyword on the method) or you use the new keyword on your overloading method.. And I got wondering if there was a way to do it in Java.
In some ways, I think that the C# philosophy is very, very bad. What if I want to overload Object.toString()? Unless Object.toString() is defined as virtual or you use the new keyword on your overloading method, you will always get Object.toString(). However, in other ways, I like the flexibility C# provides me in being able to do it both ways.
Anyway...purely academic at this point. Thanks for your help!!
18 years ago

Originally posted by Michael Matola:

This is similar to my bad code scenario above. If a grandchild thinks it needs to subvert its (immediate) parent and use its grandparent's version of a method that the parent overrode, then it's time to consider whether the parent's overriding was appropriate to begin with.


But I can only use super in DodgeRam (the child class) and NOT in a class that instantiates Truck and/or DodgeRam. Correct?
If this is correct, then the answer to my question is "You can't do that". And I'm fine with that just as long as I know that I can't do it.
If I'm not correct, please explain.
[ May 23, 2002: Message edited by: Jason Kilgrow ]
18 years ago
Ok. I realize that this is a very old thread. But, I have a question now that I've searched this topic out.
What if I WANT to call a method on the superclass? Let me explain a bit more...
public class Truck
{
public string truckMethod()
{
return "truck method";
}
}
public class DodgeRam extends Truck
{
public string truckMethod()
{
return "Dodge Ram method";
}
}
public class MyClass
{
public static void main(String[] args)
{
Truck t1 = new Truck();
System.out.println(t1.truckMethod());
DodgeRam dr1 = new DodgeRam();
System.out.println(dr1.truckMethod());
Truck t2 = new DodgeRam();
System.out.println(t2.truckMethod());
}
}
The output will look like:
truck method
Dodge Ram method
Dodge Ram method
Question:
Can I get t2 to call the superclasses truckMethod in MyClass? Nevermind the obvious "Why would I want to do this." I can't answer that question. This question arose from my study of C# and I'll just leave it at that.
Is it possible to get t2 to use Truck's truckMethod?
18 years ago
Welcome, Scott! I'm looking forward to some good discussion on XML and related technologies this week.
I'm sort of new to the whole XML world. I mean, I know what it is and I've read about how great it is, etc. And I've even used SAX and DOM to sort of get familiar with how the parsers work. That's about the extent of my knowledge on XML. I consider myself a greenie.
One thing that I see as as severe limitation, though, is the lack of browser support. For instance, I'm a web developer and if I wanted to write a web application that extracts data in an XML format, I really can't rely on the browser to accurately display that data even if I use XSLT to transform it into html. Please reel me in if I'm wrong about this.
Do you see this lack of browser support as a critical issue?
I'm not exactly sure where this belongs so I figured that I would start in the beginner section and if this belongs in a different area I hope the sheriff goes easy on me. I've also searched the javaranch archives and I can't find any discussions that fit. Anyway, here goes...
I have a bit of a quandary. Please consider the following two classes:
<pre>
class Word implements java.io.Serializable{
int i;
public void setI(int ii){
i=ii;
}
public int getI(){
return i;
}
}
</pre>

and
<pre>
import java.io.*;
public class TestSerial{
public static void main(String [] args) {
try{
FileOutputStream fout=new FileOutputStream ("t.tmp");
ObjectOutputStream out=new ObjectOutputStream(fout);
Word wd=new Word();
wd.setI(234);
out.writeObject(wd);
wd.setI(345);
out.writeObject(wd);
out.flush();
fout.close();
FileInputStream fin=new FileInputStream ("t.tmp");
ObjectInputStream in=new ObjectInputStream(fin);
System.out.println("word: " +((Word)in.readObject()).getI());
System.out.println("word: " +((Word)in.readObject()).getI());
fin.close();
}
catch(IOException e){
System.out.println(e);
}
catch(ClassNotFoundException fe){
System.out.println(fe);
}
}
}
</pre>

Now it seemed to me that the output should have been:

234
345

But it wasn't. It was:

234
234

There has been some discussion on the email list "JDJList" but nothing that has definitively explained (to me) what's going on here and why. So, I've brought it into the saloon to see what happens when we kick it around in here.
Let me recap a bit what has already been stated on JDJList:
1. In order to get the effect I want, I have to create two objects and set one object's value to 234 and the other to 345. Then I get the effect I'm looking for.
My question: why?
2. When you are dealing with object serialization you are dealing with an object's identity. Object serialization won't let you recreate an object that is already created. Therefore, once you serialize it, it's that way forever for that one particular identity.
My question: why?
Of course, I'm paraphrasing what's been said by other people. But my question is the same: why did the designers decide to do that? Why can't I serialize, change the value, and then re-serialize an object? What is the purpose? Maybe the answer is staring straight at me and I'm too thick to see it but I just don't understand. Can anyone shed light on this?
18 years ago

Originally posted by James Hart:
Generics is a proposed amendment to the Java type system that allows you to write classes in such a way that they can handle any kind of object in a type-safe manner.


OH! Okay! I HAVE heard of generics then. I just didn't know what they were called. Generics is sort of Java's answer to C++ STL.
Thanks for the explanation. I think it will improve the type system a lot!
18 years ago

Originally posted by Cindy Glass:
Mechanically generated source code often uses a representation that preserves Binary compatability.


It sounds like we're looking at decompiled code then?
18 years ago
To add to what Pho said, some applications treat classes differently if they are serializable (they implement Serializable). For instance, BEA Weblogic server can be clustered for load balancing/fail over situations so that clustered servers share the workload. In this type of environment, it is essential that objects that need to be replicated on all clustered servers implement the Serializable interface. The server enforces certain rules about these objects. Mainly, that all objects in these serializable objects implement Serializable as well. Sometimes this causes us to change our development strategy (that's another discussion).
The point is that the Weblogic server treats serializable objects differently than non-serializable. It's quite a useful pattern.
18 years ago
Thanks David and Jim!
I'm going to try them out!
18 years ago

Originally posted by David Garland:
Speaking of assertions being in/excluded in production versions, does anyone know how Java will handle this?


From the article on JavaWorld that was mentioned earlier, it sounds to me like they are going to be used in a production environment. Not like C++ assertions at all. That's just my interpretation of what I read in the article.
18 years ago

Originally posted by James Hart:
...Maybe the introduction of a fundamental language change like generics is enough to justify it


What is/are "generics"? I am unfamiliar with that term/concept.
18 years ago

Originally posted by karl koch:
hi,
and what are asserts ? never heard this before in this relation. so if anybody has the time to enlighten me......:-) feel free.
thanks
k


Use asserts during testing/debugging when you are sure that a condition should never exist and wouldn't kill the program but you want the program to die if the condition ever does happen.
Is that about it in a nutshell?
That's a good article and it sounds like Java asserts are going to be a bit more than just a debugging/testing tool.

[This message has been edited by Jason Kilgrow (edited December 19, 2001).]
18 years ago

Originally posted by James Hart:
Speaking of games (of a completely different kind), by the way, has anyone here had a chance to play with RoboCode (http://robocode.alphaworks.ibm.com/)?


I installed RoboCode a couple of days ago. From the little bit I've played with it, it rocks! That's going to be fun and educational!
I haven't heard of it yet, but I'm thinking that battling robots via the web would be a cool project to work on.
[This message has been edited by Jason Kilgrow (edited December 19, 2001).]
18 years ago

Originally posted by James Hart:
I'm interested to know, though - are XML and XSLT skills just an accepted part of being a Java programmer nowadays? Should I have assumed that readers of the book were already familiar with JAXP?


NO! I think XML is still underused and understated. I find myself wanting ever more exposure to XML and XSLT. I know that they do more than the little I know about them.
18 years ago