cast java code example
Example 1: java type casting
int SomeNumber = 5;
double WideCastedNumber = (double)SomeNumber;
double SomeNumber = 5.39;
int NarrowCastedNumber = (int)SomeNumber;
Example 2: cast java
JAVA: Example of cast:
int SomeNumber = 5;
double WideCastedNumber = (double)SomeNumber;
double myDouble = 9.78;
int myInt = (int) myDouble;
Example 3: casting in java
Byte-->short-->char-->Int-->long-->float-->double
Example 4: casting in java
Primitive Type casting and Reference Type casting
PRIMITIVE CASTING:
implicit casting (casting smaller type to larger
int a = 100; double c = a;)
explicit casting (casting larger to smaller
byte b = (byte) a;
REFERENCE CASTING:
upcasting - implicitly done (casting smaller type to larger)
Collection<Integer> collection = new ArrayList<>();
downcasting (cast larger type to smaller one )
List <Integer> list = ( ArrayList ) collection;
FRAMEWORK EXAMPLE:
Up Casting, Down Casting in Multi Browser testing.
WebDriver, Chrome Driver, Firefox Driver object
I casted to WebDriver to making reference type.
Whenever you taking Screenshots,
whenever executing Java script command.