Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!

Claud Mann

Ranch Hand
+ Follow
since Apr 14, 2020
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Claud Mann

Good evening everyone, I have a question for you:

Let's consider a class Y and a subclass of Y named X.

My question is:
in the subclass X, I can use "var" and "super.var" as two distinct and completely separated attributes, a.k.a. which are not linked?
4 days ago

Junilu Lacar wrote:

In this case X is the super class and Y is the sub-class.
An object whose declared type is Y is also an object who can fit wherever an X object is expected, because of substitubality, right?
This is the reason why casting is not necessary.
Viceversa, an object whose declared type is X need a cast because it is not guaranteed that it will fit wherever an object of Y type is expected, right?
4 days ago

Campbell Ritchie wrote:

Claud Mann wrote:. . , I edited the post. . . .

Kindly don't make that sort of change; I have reverted it. Yo managed to introduce a new error into that post by editing it.other

Ok no problem
4 days ago

Junilu Lacar wrote:
It is still X. Casting does not change the type of a reference variable, it allows you to assign that reference to another reference.

I think this sentence has definitely clarified my doubts about my Upcasting.
4 days ago
Good evening everyone, I have three questions for you which regard downcasting.

1)The reason why downcasting is useful is that an object of a superclass. after being down-casted, it will be able to access ALL the methods of a specific lower class?

2) I read a sentence on a book that I didn't understand.  Here it is:
"Downcasting is not always safe because a node might have more than one child. If you cast to the wrong child, a ClassCastException will be thrown. "
Can anyone explain me this sentence? I don't understand why, if a node has more than one child, the downcasting could be not safe.

3) I read that when I use downcasting, the use of "instanceof" inside a if-case is a MUST.
I have to use the if-case even if I downcasted the object just some lines before?
I make an example:

Let's consider a class Y and its sub-class X

Is the if-case recommended in this case?
4 days ago

Junilu Lacar wrote:That's not valid syntax. You can only cast to a type, not a variable. If you meant (Y) x, then casting will never change the actual object type. You should give an example that compiles so it's clear what you're trying to do. Otherwise, people will just have to infer your intent and that inference may or may not be what you actually intended.

Thanks for your answer Junilu, I edited the post.

The code I would write is simply this:

after that I declare the class Y and the class X

after the third line on, the reference type of "x" will be Y?
4 days ago

Junilu Lacar wrote:

Super! thanks.

4 days ago
Good evening everyone, I have a questionf for you.

Let's consider a class Y and a subclass of Y named X.
Let's consider also the case where I instatiate an object "y" which has Y as type of reference, and an object "x" which has X as type of reference.

When in a line of code I do explicit casting, namely:


the object "x", from that specific line of code on, will have as type of reference Y?
Or it will have Y as type of reference only in that specific line of code?
4 days ago
Good evening everyone,

I have two questions for you which regard objects.

1) Are objects instantiable only inside methods? An object can't be instantiated inside a class, but outside methods, right?

2) To instatiate objects which belong to a specific Wrapper Class, I have to use the keyword "valueOf" instead of "new", right? Can anyone explain me why does this happen?
4 days ago
Thanks again to everyone.
4 days ago

Campbell Ritchie wrote:...o it can't be changed to support generics. You can pass an Object[] to it where Object doesn't implement Comparable and the compiler will be happy and you will suffer a class cast exception at runtime. Link 2 doesn't have these problems.

thank you very much Campbell
4 days ago
Good evening everyone.

I have a question for you.

If I want to order a collection of objects which belong to the class "A", I have to use the method "sort".
If I want to use the method "sort", the class A has to implement the interface Comparable and define the method compareTo.

Does the same goes for the method sort of the arrays (in the case I want to create an array of objects)?
1 week ago

Junilu Lacar wrote:
It's kind of like seeing humans with a biology lens (humans belong to the animal kingdom and are mammals) vs. with a chemistry lens (humans are carbon-based and are up to 60% H2O). Both these ways of looking at humans are correct. Your question, however, is like saying "I thought humans belonged to the animal kingdom so how can they also be carbon-based?"

Thanks to Campbell and Junilu!
So, let me know if this sentence is correct:
a collection is a particular kind of class which is able to "collect" some objects.
Is it right?
1 week ago
Good evening everyone,

I'm studying Java Collection Framework.
It is composed by interfaces and its implementation.
I give you an example which will bring to my doubt.

In JCF we can find:
The interface List and its implementation ArrayList.
I can create a new collection of objects writing:

Collection<String> names = new ArrayList<>;

Can anyone explain me the difference between an interface and its implementation, and, being more spefic:
what is an implementation of an interface?
1 week ago