[jug.bg] Valhalla hackaton (29.01.2015)

Today we had a second bgjug hackaton for the month. Its topic was Valhalla.

Project Valhalla will probably be part of Java 10 (expected 2018). Among other things it allows using primitives as generic arguments.

Here's how you can build Valhalla yourself.

Here's a virtual machine with valhalla if you're lazy (virtual box).

This is the valhalla presentation by Ivan. And this is the video of the talk (in Bulgarian).


Here are some of the code we ran:

Ivan created a simple ArrayList

public class SpecialArrayList {
	private static int INITIAL_SIZE = 10;
	private T[] elements = null;
	private int length = 0;
	public SpecialArrayList() {
		elements = new T[INITIAL_SIZE];
	public T get(int position) {
		if(position >= length) {
			throw new ArrayIndexOutOfBoundsException();
		return elements[position];
	public void add(T element) {
		// Check whether array is full
		elements[length] = element;
public class Main {
	public static void main(String[] args) {
		SpecialArrayList intList = new SpecialArrayList<>();
		SpecialArrayList stringList = new SpecialArrayList<>();

Nayden tested a bit of crazy code - which is supposed to fail (IA impl = new IAImpl();):

public class B  {
   protected T t;
   protected T[] ts;
   public B(){}
   public B(T t){
     this.t = t;
     this.ts = new T[100];
   //  System.out.println(this.t.getClass());
   public T[] getTs(){
     return this.ts;
   public T getT(){
     return this.t;
   public static void main(String[] args){
       B b = new B<>(100);
       System.out.println((new B("dada")).getClass());
       IAImpl ludnica = new IAImpl();
       System.out.println(ludnica.getT() instanceof Object);
       IABase base = new IAChild();
       IA impl = new IAImpl();
interface IA{
 public T getT();
 public void setT(T t);
class IABase{
 private T t;
 public T getT(){
   return this.t;
 public void setT(T t){
   this.t = t;
class IAChild extends IABase {
class IAImpl implements IA {
 private Object t;
 public Object getT(){
   return this.t;
 public void setT(Object t){
   this.t = t;

6 thoughts on “[jug.bg] Valhalla hackaton (29.01.2015)”

  1. Hi Ivan, BGJUG,

    Nice blog post, I have only caught up with my OpenJDK mails.

    Could you please post the output of this program on your post - it can help others verify if they are doing it right.

    Good work - I'll add these and other links to your Adopt OpenJDK book.


Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.