This article was originally written in Russian and published on September 12, 2016 at Habrahabr
Static methods have one powerful and not very desirable feature: they can be invoked from any place of the code, and they also can't really dictate the order of such invocations.
Usually such control is really important, but sometimes the real order does not make much sense.
For example, assertions and verifications in unit tests often do not require to be executed in strict order.
To ensure that all verifications are done, Mockito provides a static method named
Sometimes, accidentally, this method can be invoked before the last
verify(...) is invoked so a bitter "red" test will be the result.
But what if delegate the verification order check to the compiler?
Sometimes, usually on Fridays, there is nothing to do. And I always missed a very cool feature of meta-programming in Java. Well, Java is not very excited about making changes in the core language, so we can make some fun with meta-programming ourselves. Let's take a look at a Java and C preprocessor example. And remember, it's just for fun and nothing else. :)
Can you spot a mistake in the code below?
StringBuilder sb1 = new StringBuilder("0"); StringBuilder sb2 = new StringBuilder('1'); System.out.println(sb1.append(sb2).toString());
The original question was originally posted on August 27, 2016 at Android StackExchange
Recently I've faced with a problem of migrating applications and their data from one device to another. Backing up and restoring is not a hard think, at least it should not be. However, standard Android approach may not work as expected causing weird issues. Let's take a look at one of them.
The next month marks 12 years since my first crack. I feel a kind of old. It was a nice period trying to find something new everyday. Software cracking was among them. Despite I have never been skilled in cracking and all my old cracks are quite simple, I still respect reverse engineering guys very much.
Recently I've became a fan of an Android game called Jewels Saga. I didn't use any cheats and I could reach the 198th level being stuck on the 197th level. However I couldn't walk through the level for more than a week, so...
This article was originally written in Russian and published on August 11, 2016 at Habrahabr
Spring Security is a must-have component for Spring applications as it's responsible for user authentication and system activity authorization.
The use of
@PreAuthorize is one of Spring Security methods allowing to define some authorization rules easily, and these rules can grant or deny some operation for a particular user.
The REST service I currently develop has to provide an endpoint to list all controller methods authorization rules.
And, if possible, avoid revealing the specifics of SpEL expressions (so, use something like
anybody instead of
principal at all as an excessive expression), but return custom expressions we can process whatever we want.
The original question was originally posted on May 17, 2015 at StackOverflow
This article was originally written in Russian and published on September 15, 2015 at Habrahabr
Java 8 was released in early 2014 featuring some pretty convenient new features to simplify trivial coding and letting the developers to simplify their lives. Some of them are lambda expressions, method and constructor references, interface default methods as the Java language and JVM extensions, and the Stream API for JDK. Unfortunately, slow introduction of such new features has a pretty negative impact on another Java-oriented platforms. GWT and Android still lack the Java 8 language features official support. However, the last spring GWT 2.8.0 SNAPSHOT versions have lambda expressions support already. Android things are still different since lambda expressions rely on the Android Java runtime, and not just the compiler. But Maven 8 lets to solve the Java 8 use problem relatively easy.