forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConversionsEx.java
More file actions
53 lines (35 loc) · 1.31 KB
/
ConversionsEx.java
File metadata and controls
53 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.zetcode;
import java.util.Objects;
public class ConversionsEx {
public static void main(String[] args) {
// https://stackoverflow.com/questions/1514910/how-to-properly-compare-two-integers-in-java?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
Integer m = 4;
Integer n = 5;
if (Objects.equals(m, n)) {
System.out.println("Variables are equal");
} else {
System.out.println("Variables are not equal");
}
if (m.intValue() == n.intValue()) {
System.out.println("Variables are equal");
} else {
System.out.println("Variables are not equal");
}
// you can't convert-and-autobox in one step
// you can't implicitly narrow a type
// 1L
Long num = 1L;
// Why new Long(10) compiles? Because there is a suitable constructor
// available that excepts integer arguments.
Long num2 = new Long(2);
Byte b = new Byte((byte) 10);
byte b2 = 34;
Long x = (long) 10;
int x2 = (int) 23.4;
double x3 = 23;
double x4 = 32f;
float x5 = (float) 35.567d;
byte g = (12) * 3;
//byte g2 = 3 * g;
}
}