Translating java static field to Kotlin


#1

I am porting Artemis Entity Framework (game related) to Kotlin and I encounter a problem in trying to replace a java static field to Kotlin equivalent

package com.artemis;
 
public class ComponentType {
        private static long nextBit = 1;
        private static int nextId = 0;
        
        private long bit;
        private int id;
        
        public ComponentType() {
                init();
        }
        
        private void init() {
                bit = nextBit;
                nextBit = nextBit << 1;
                id = nextId++;
        }
        
        public long getBit() {
                return bit;
        }
        
        public int getId() {
                return id;
        }
}

to

package artemis
 
private var nextBit : Long = 1
private var nextId : Int = 0
 
public class ComponentType{
    private var bit : Long = 0
    private var id : Int = 0
 
    {
        bit = nextBit
        nextBit = nextBit shl 1
        id = nextId++
    }
 
    public fun getBit(): Long{
        return bit
    }
 
    public fun getId() : Int{
        return id
    }
}

This will generate runtime error at statement "bit = “nextBit”


#2

Looks like a bug. Could you report it to our isse tracker? Thanks


#3

http://youtrack.jetbrains.com/issue/KT-2292