Search code examples
javadatabasekdb

java kdb - casting C to string


I am trying to cast kx.c class flip object to a string:

String test = (String) c.at(flip[0],1)

However I am getting an error stating that I cannot cast C objects to String. Does anyone know what I can cast a kx C object to return a string?


Solution

  • Not too sure what you mean exactly by "C objects" but I assume that it is a char array - the Java type to represent a Kdb string. Here is what you can do:

    Object[] data = this.flip.y;
    Object[] columnData = (Object[]) data[row];        
    char[] data = (char[]) columnData[i];
    return String.valueOf(data);
    

    If you are trying to retrieve a kdb symbol then it will be a String array.

    Object[] data = this.flip.y;
    Object[] columnData = (Object[]) data[row];        
    String data = (String) columnData[i];
    return data;