Fighting with Java - generics

Java generic types are not true types actually, so it’s not possible to have few constructors to accept same type with different generic parameters, because it will have same signature. For example if you need to accept Iterable<String> and Iterable<Text> in constructor, you can’t just add two constructors for these types, because it won’t even compile. In this post I’ll show you how I usually deal with this situation.

Read More

Object equality (Java)

Each object in java has two methods to check object equality: it is Object.equals(Object other) and Object.hashCode(). Often developers override these methods so they can store instances of Object subclasses in hash-based collections e.g. HashMap, HashSet etc. I don’t like this design where each object can be compared for equality with any other object, but in this post I’ll not criticize it, rather I’ll try to demonstrate how to implement it correctly for object oriented code.

Read More

Release Docker with Rultor

Rultor is a great bot to automate development life-cycle: just post a comment in a GitHub ticket and your project will be released. Also it can merge pull-requests and deploy code to production but now I want to speak about how to release a Docker image.

Read More

Get rid of presenter

How to split platform depended views from domain logic and be able to unit-test them separately? There are few ways to do it, one of them is MVP (Model-View-Presenter) pattern. It gives us many advantages in Android system but has one major drawback in OOP world - a presenter.

Read More

Fully encapsulated

Let’s speak about common domain objects and how they are usually implemented. The tendency here is to define a bunch of accessors to share object’s state and returning nulls as an indicator of empty value. In this post I will try to refactor one of this objects to fully encapsulated one!

Read More

Database (part one)

It’s an open secret that almost every Android application stores something in a database. Nearly always it is SQLite.
In my practice I’ve tried many ways to work with sqlite in Android: it was some ORM and active-record libraries, ContentProvider’s, even some wrappers for native .so libraries. But with none of them I was satisfied.

Read More