Posts

Showing posts from April, 2014

Maven: Report deprecated API & unchecked method invocation

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <compilerArgument>-Xlint:unchecked</compilerArgument> <showWarnings>true</showWarnings> <showDeprecation>true</showDeprecation> </configuration> </plugin>

For-each loop vs Iterator vs C-style for loop

In Java a for loop that uses an iterator List<String> strings = new LinkedList<>(Arrays.asList("first", "second")); for (Iterator iterator = strings.iterator(); iterator.hasNext();) {     System.out.println(iterator.next()); } is essentially the same as List<String> strings = new LinkedList<>(Arrays.asList("first", "second")); for (String string : strings) {     System.out.println(string); } because the generated byte code for the second code snippet executes the same operations underneath as for the first code snippet. So the for-each loop , introduced with Java 5 is merely syntactic sugar for the for loop that explicitly deals with an iterator. However this C-style for loop  works with an index List<String> strings = new LinkedList<>(Arrays.asList("first", "second")); for(int index = 0; index < strings.size(); index++) {      System.out.println(strings.get(index));

Manipulate / change git' commit timestamp

After doing a regular commit, issue this command: git commit --amend --date="Mon Apr 7 07:33 2014 +0200"