trait mixin java inheritance behavior interfaces
In my last post I’ve presented both traits and mixins, with the promise of identifying the Java 8 Interface Default Methods. So, let’s get on it.
First of all, if you don’t know what I’m talking about, read my previous post -and please ignore the fact that it took me almost half a year to write this second part :)
A quick summary:
Mixins: Abstract subclasses. You can call super
from inside the mixin, and can define both methods and variables. Mixins automatically solves conflict by linearization (inserting the mixin in the method lookup chain from left to right).
Traits: Allow us to define behaviour outside the class, but don’t define state. The methods defined in the trait «have the same semantics» as the method defined in the class (Flattening property). It’s like they were copied into the class. You have to handle conflicts by yourself.
Now we can fully dive into Java Interface default methods.
19 May 2015
On the first part of this article I explained why java generics don’t allow up-casting for generified types. In this part we will see why, arrays don’t have that restriction, and the implications for reflection.
If generified lists aren’t allowed to up-cast, why arrays are?
The reason is very simple: arrays don’t erase their element type. At runtime, each array knows exactly which kind of element it should allow in. If you try this code:
String[] stringArray = new String[1];
Object[] objectArray = stringArray; // Perfectly normal
The compiler allows you to up-cast. What if we try to put something in the string array, that is not a string?
2 Dec 2014
When you use a compile-time typed language, like Java, you expect that types in each variable will help you by restricting the possibilities for a value. Instead of being able to do everything, you want to do things that are valid in your domain.
Discussions aside about strong vs weak typing, when you code with types you think of types as sets. A variable can be one of the elements of the implicit set for its type. Thus Integer a
means that variable ‘a’ will be one of the elements in the Integer set, and only that.
If you have a String variable ‘a’ and want to assign its value to a variable ‘b’ of type Object:
String a = "A";
Object b = a;
2 Dec 2014
trait mixin java inheritance behavior interfaces
A couple of days ago, a discussion came up in an uqbar foundation[^1] mailing list about the Java 8 Interfaces Default Methods. They were named as «mixins», but I corrected them and called «traits without flattening».
After sending the mail, that last sentence kept ringing in my head, so I proposed myself to try to understand why was I calling them like that. But first things first.
14 Oct 2014
The answer is: of course not!!, but now that I got your attention surely due to the title that mimics the lately hot [“Is TDD Dead?”][is-tdd-dead] discussion started by [@dhh][dhh], I would like to concentrate on the real objective of this post that I think it is really more important: is Java taking the right road? or in other words, are the last changes in Java 8 “good” ones or not?
5 Jun 2014
jvm framework java concurrency
Akka es un framework para programación concurrente, distribuida y tolerante a fallos en la JVM, principalmente basado en Scala pero que también soporta Java. Akka implementa el modelo de Actores (http://en.wikipedia.org/wiki/Actor_model) que se basa en entidades llamadas Actores que se ejecutan concurrentemente y se envían mensajes de forma asincrónica entre sí. Este mismo modelo es el que implementa el lenguaje de programación Erlang. Akka también implementa Software Transactional Memory, un mecanismo de memoria transaccional que es una alternativa al locking para acceder a estructuras de datos en memoria compartidas, y que es similar al que está implementado en el lenguaje Clojure.
En este articulo, veremos como utilizar Akka en Java, utilizando Actores y STM para resolver un problema de concurrencia simple pero que involucra multiples variables que se actualizan a la vez, con un cierto nivel de contención. Vamos a ver varias implementaciones, explorando las posibilidades de Akka, con el código fuente disponible para bajar. Utilizaremos la versión Akka 1.2.
29 Feb 2012
What if the application were aware of its different running environments so it could change its configuration automatically based on the current one?
23 Feb 2012
El protocolo **FIX ** (Financial Information Exchange Protocol) es un protocolo de mensajes para el comercio de instrumentos financieros. FIX se utiliza ampliamente para la comunicación automática entre los participantes del intercambio de instrumentos, y especifica como son los mensajes para crear ordenes de compra y venta y consultar cotizaciones de instrumento, entre otros. Este protocolo es el que hay que utilizar para comunicarnos con practicamente todos los mercados financieros de manera electrónica.
En este articulo, veremos los aspectos básicos del protocolo FIX, como utilizarlo mediante la librería de java QuickFIX/J mediante un ejemplo como cliente y servidor, y algunos aspectos poco obvios que hay que tener en cuenta al utilizarlo.
21 Nov 2011