Skip to content

Commit 6874ac4

Browse files
committed
Remove unnecessary null comparison
1 parent 5a1c8d9 commit 6874ac4

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

prototype/prototype.dart

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
abstract class Shape {
2-
int x;
3-
int y;
2+
late int x;
3+
late int y;
44
Shape clone();
55
}
66

77
class Rectangle implements Shape {
8-
int height;
9-
int width;
10-
int x;
11-
int y;
8+
late int height;
9+
late int width;
10+
late int x;
11+
late int y;
1212

13-
int _hashCode;
13+
late int _hashCode;
1414
bool isClone = false;
1515
String get cloneStatus => isClone ? "is a clone" : "is an original gangster";
1616

@@ -32,7 +32,6 @@ class Rectangle implements Shape {
3232

3333
@override
3434
int get hashCode {
35-
if (_hashCode != null) return _hashCode;
3635
_hashCode = DateTime.now().millisecondsSinceEpoch;
3736
return _hashCode;
3837
}

proxy/proxy.dart

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ abstract class Subject {
33
}
44

55
class ExpensiveClass implements Subject {
6-
String name;
6+
late String name;
77

88
ExpensiveClass(this.name);
99

@@ -13,8 +13,8 @@ class ExpensiveClass implements Subject {
1313
}
1414

1515
class Proxy implements Subject {
16-
String _name;
17-
ExpensiveClass _sub;
16+
late String _name;
17+
late ExpensiveClass _sub;
1818

1919
Proxy(this._name);
2020

@@ -24,7 +24,6 @@ class Proxy implements Subject {
2424
}
2525

2626
ExpensiveClass _subject() {
27-
if (_sub != null) return _sub;
2827
print("Creating an instance of ExpensiveClass for the proxy...");
2928
_sub = ExpensiveClass(_name);
3029
return _sub;

0 commit comments

Comments
 (0)