Dollar dollar = (Dollar); What does it do?

Dollar dollar= (Dollar) object; 

What does this piece do? Is it even Java? Or Smalltalk? I found it in TDD, which I think was written with Smalltalk.

+4
source share
3 answers

It could be Java. It basically throws an object of a generic type (perhaps only an Object) into a Dollar object.

Example:

 Object object = ObjectFactory.getObject(); // Gets object Dollar dollar = (Dollar) object; // Cast to Dollar object, will throw an exception // if this isn't possible dollar.dollarMethod(); // I can now call Dollar methods 
+9
source

Creates a new Dollar class variable named dollar. He then assigns the value to this variable by translating into Dollar a variable named object. This is valid Java code, providing a class called Dollar there. But if a variable called object does not belong to the Dollar class, this may throw a ClassCastException.

+4
source

this actually distinguishes the generic type (Object) from the dollar type.

0
source

Source: https://habr.com/ru/post/1314733/


All Articles