Sriram selvaraj

Greenhorn
+ Follow
since Nov 28, 2008
Merit badge: grant badges
For More
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 Sriram selvaraj

Devaka Cooray wrote:I wrote this article. Hope that helps.



Cant ask for a better explanation. Thank you so much.

Jacob Sonia wrote:i thought one cannot add anything when using ?



No Sonia, if it is a plain ? or ? extends , then we cannot modify the list. But if we use ? super , then we can modify the list. In my example, I am able to add an Integer instance to the list but when I try to add an Object instance I am getting a compilation error.

Interestingly, when i try to assign an Object array, it is getting assigned perfectly.




Can anyone help me in understanding the behavior here.


Why is compilation failing though Object is a super class of Integer.



I understood now. Thanks Tanya for the detailed explanation. Thanks for all the ranchers for the prompt replies.

Mo Jay wrote:If you want the method to do what you say then you should provide some method overriding for it where you can just copy the exact getName() method from the parent A to the subclass B and at that point B will be return it in the output. Remember that the copy you have of getName() method is a copy of the A class and class B did nothing to override or change that implementation, if you just expect the method to be inherited and magically to pick instance variable of the subclass then it is not going to happen that way.

You (the programmer) need to specify what the method should and what the output should look like by providing an implementation for it.



Mo Jay, thank you for all your prompt replies. I understand that, since there is no implementation for getName in class B, it takes the parent's implementation. What I do not understand is

1. Instance as well as the variable type is of type B, so when getName is invoked, should it not take the value of name from B?
2. Again, this.name should be ideally pointing to B's reference because the instance and variable is of type B.



Thanks again everyone. And sorry if I sound a little dumb, I am really not able to get the underlying point behind this.

Mo Jay wrote:I don't see any shadowing here, since you didn't provide any implementation of the getName() method in the B class then you will get the one from the parent class A. If you provide the implementation of that method in class B then you should get the output as A:B

Cheers!!!



Even if it uses A's implementation, the instance is of type B, so should it not use B's name ?

Hi Ranchers,
Can anyone explain me the reason behind the output of the following code,


Result: A:A

Why did we not get A:B

Thanks in advance.
I have left and right pane in my screen. Left will have a tree and clicking the tree will show a form in the right side pane. I have few mandatory fields
in my form.

The problem I face is, if I submit the form with some mandatory fields empty. I am getting validation error with required message as expected.

The strange behavior is, when i click on the left side tree link to populate values in the form after getting validation problem. Only those fields which failed validation gets updated with proper values leaving the values which we entered in mandatory fields unchanged.

I will give an example to make you better understand.

1. Consider the left side tree has a list of students and right side
form has First name and Last name.

2. If you try to add/modify a student with empty Last name, you will
get "Last name required" message.

3. Now if you try to click on a different student from the tree, only
Last name which had a validation problem previously will be
properly populated and First name will always be the same which
was there during the validation problem.

Please let me know what I should do solve this issue. This is becoming critical to solve day by day.

Thanks in advance.
15 years ago
JSF