[Vala] inheritance and specialisation of generic class



Hi, I've got a strange behavior using this code.

When I create a instance of Gee.List in base class, the objects add into the list seem to be freed at the end of the block (create).
To fix the issue I must instantiate the list into the subclass.

If I don't define the class AbstractPeer as abstract, I obtain this error :
too few arguments to function 'abstract_peer_construct'

thanks.

using GLib;

public class Task : Object
{
    public int64  id   {get; set;}
    public string name {get; set;}

}

public abstract class AbstractPeer<G>: GLib.Object
{
    public         Gee.List<G> iterator;
       
    construct {
        this.iterator = new Gee.ArrayList<G>();
    }
}

/**
 *
 */
public class TaskPeer: AbstractPeer<Task>
{
    //Uncomment to fix the problem
    /*construct {
        this.iterator = new Gee.ArrayList<Task>();
    }*/
   
    public void find() {

        this.create();
        this.create();
        this.create();
    }
   
    public void create() {
        Task task = new Task();
        task.name = "test" + this.iterator.size.to_string() ;

        this.iterator.add(task);
    }
}

public class Main
{
    static int main(string[] argv) {
       
        var peer = new TaskPeer();
        peer.find();
       
       
        for(int i =0; i<peer.iterator.size; i++) {
            Task task = peer.iterator.get(i);
           
            stdout.printf("Task %d : [%s] %s\n", i, task.get_type().name() , task.name);
        }
       
        return 0;
    }
}



Ne pleurez pas si votre Webmail ferme. Récupérez votre historique sur Yahoo! Mail

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]