The behavior of the assignment operator is different. Swift is 5 (online environment for the time being because there is only Windows)
While studying Swift, I wondered, "Is it possible to use Java as an assignment operator with Swift?"
Test1.java
try {
final File file = new File("src\\test.txt");
try (final BufferedReader reader = new BufferedReader(new FileReader(file))) {
String str;
while((str = reader.readLine()) != null) {
System.out.println(str);
}
}
} catch (IOException e) {
e.printStackTrace();
}
In the part of (str = reader.readLine ())! = null
, substitute the result of reading one line into str.
The assignment operator returns the assigned value, which means that it compares null with the string resulting from reading one line.
It ’s simpler,
Test2.java
int a = 1;
int b = a = 2;
This substitutes 2 for a, and then a = 2 returns the assigned value. In other words, b contains 2.
So I tried it with Swift.
test1.swift
var a = 10
var b = a = 10
print(a)
print(b)
Then.
10
()
** b is now a tuple. ** ** Is this really a tuple? It's time ...
test1.swift
var a = 10
var b = a = 10
print(b == ())
Then.
True
** It was really a tuple. ** ** (I wondered why I would return the tuple, but I didn't care) I thought I might have done it without knowing it, so I made a note.