Using the Deprecated annotation

The @Deprecated annotation can be used to indicate elements which should no longer be used. Any program that uses an element which is marked as @Deprecated will produce a compiler warning. @Deprecated public void oldMethod() { ... } public void newMethod() { ... } In this examples, newMethod replaces oldMethod. However we do not want to remove oldMethod completely because keeping it will help maintain backwards compatibility with older versions of the program....

April 18, 2017 · 1 min · Rezha Julio

Diamond Operator in Java

Since Java 7 it’s not necessary to declare the type parameter twice while instantiating objects like Maps, Sets and Lists. Consider the following code: Map<String, List<String>> phoneBook = new HashMap<String, List<String>>(); The type parameter for HashMap in the right hand side of the expression seems redundant. This can be shortened using an empty “Diamond Operator” to give: Map<String, List<String>> phoneBook = new HashMap<>();

April 17, 2017 · 1 min · Rezha Julio

Lambda Functions in Python

The lambda keyword in Python provides a shortcut for declaring small anonymous functions. Lambda functions behave just like regular functions declared with the def keyword. They can be used whenever function objects are required. For example, this is how you’d define a simple lambda function carrying out an addition: >>> add = lambda x, y: x + y >>> add(5, 3) 8 You could declare the same add function with the def keyword:...

April 16, 2017 · 5 min · Rezha Julio

Altering format string output by changing a format specifier's argument_index

A format string is a string which can include one or more format specifiers. String hungry = "hungry"; String hippo = "hippo"; String s = String.format( "%s %s", hungry, hippo); Here, “%s %s” is a format string, and %s is a format specifier. The value of s is “hungry hippo”. Modify the order that the arguments appear in the format string by specifying an argument index in the format specifiers....

April 15, 2017 · 1 min · Rezha Julio

Add Autocorrect to Git

If you want git to correct typos you can set help.autocorrect: $ git config --global help.autocorrect 30 You set help.autocorrect to an integer representing the time you have to change your mind before git executes the command (1 = 0.1 seconds). For example: $ git comit WARNING: You called a git command named 'comit', which does not exist. Continuing under the assumption that you meant 'commit' in 3 seconds automatically...

April 14, 2017 · 1 min · Rezha Julio