Inherit properties

26 views
Skip to first unread message

Alexander Sommer

unread,
Sep 13, 2014, 3:17:59 AM9/13/14
to owne...@googlegroups.com
Hello!

I would like to inherit properties. 

@Sources({"file:src/main/resources/Amsterdam.properties" })

public interface AmsterdamProperties extends Config {


    @Key("price.update.time")

    public String priceUpdateTime();


@Sources({"file:src/main/resources/Barcelona.properties" })

public interface BarcelonaProperties extends Config {


    @Key("price.update.time")

    public String priceUpdateTime();


so in this example, i have 2x priceUpdateTime();


and i would like to have a parent interface which has priceUpdateTime() but for sure, loaded should it be then from amsterdan or barcelona properties.


how can i do this? would it be enough to write a parent class which is inheriting from config, having the parameter priceUpdateTime but no @sources attached?


thx

alex



Luigi R. Viggiano

unread,
Oct 2, 2014, 6:31:46 AM10/2/14
to owne...@googlegroups.com
This usage has not been designed. Have you tried to see what is the current behavior?

The problem is multiple inheritance. Since with annotations you specify how the method should work, defining two different behaviours for the same thing leads to ambiguity.

If you have:

interface SuperConfig extends Config {

    String country();


interface  Amsterdam extends SuperConfig {
    @DefaultValue("Holland")
    String country();
}

interface  Barcellona extends SuperConfig {
    @DefaultValue("Spain")
    String country();
}

interface Whatever extends Amsterdam, Barcellona {} 

when I do Whatever.getCountry() what should be returned?

Luigi.

Luigi R. Viggiano

unread,
Oct 2, 2014, 10:12:34 AM10/2/14
to owne...@googlegroups.com


how can i do this? would it be enough to write a parent class which is inheriting from config, having the parameter priceUpdateTime but no @sources attached?



As far as I understood this scenario should work properly:


public interface SuperConfig extends Config {
    public String priceUpdateTime();
}


@Sources({"file:src/main/resources/Amsterdam.properties" })

public interface AmsterdamProperties extends SuperConfig {
    Key("price.update.time")
    public String priceUpdateTime();
}


@Sources({"file:src/main/resources/Barcelona.properties" })
public interface BarcelonaProperties extends SuperConfig {
    Key("price.update.time")
    public String priceUpdateTime();
}



I'm not sure instead if the following scenario works (maybe yes!):

public interface SuperConfig extends Config {
    Key("price.update.time")
    public String priceUpdateTime();
}

@Sources({"file:src/main/resources/Amsterdam.properties" })

public interface AmsterdamProperties extends SuperConfig {
}

@Sources({"file:src/main/resources/Barcelona.properties" })
public interface BarcelonaProperties extends SuperConfig {
}


Let us know.

L.
Reply all
Reply to author
Forward
0 new messages