References¶
- Generally speaking, BufferedReader/BufferedWrite are preferred over InputStreamReader/InputStreamWriter.
https://docs.oracle.com/javase/8/docs/api/java/io/BufferedWriter.html
public static Stream\<String> java.nio.file.Files.lines¶
public static List\<String> java.nio.file.Files.readAllLines¶
Read all lines from a file.
Bytes from the file are decoded into characters using the UTF-8 charset.
Notice that this method returns a List of Strings,
which is different from the method java.nio.file.Files.lines
(who returns a Stream of Strings).
Kotlin vs Scala
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
https://www.quora.com/Is-Kotlin-so-similar-to-Scala-What-are-the-differences/answer/Bruce-Richardson-4
Loops in Java
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
-
The condition(s) in a regular
for
orwhile
loop is recomputed before each iteration. Not only the change of loop variables but also other variables involved in the loop condition …
Arrays in Java
Comments¶
- An array in Java is not an
Iterable
(due to design reasons). There is no super class of array andIterable
either in Java. If you want a method to support both array andIterable
as the parameter, you need to overload it (for both array andIterable
.) It is the same situation in Kotlin as Kotlin is mostly Java.
Example of Using Reflection in Java
Java Unit Testing
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
import static org.junit.Assert.*;
assertEquals
assertArrayEquals
Use reflection to test private methods.
References
https://javarevisited.blogspot.com/2018/09/junit-testing-tips-constructor-is-called-before-test-methods.html
https://medium.com/mindorks/how-to-unit-test-private-methods-in-java-and-kotlin-d3cae49dccd