开发者

how can I get a linked HashMap

开发者 https://www.devze.com 2023-02-20 12:10 出处:网络
I has a Args class,this class extend HashMap and has some methods: public class Args extends HashMap{ public myMethod_1(){

I has a Args class,this class extend HashMap and has some methods:

public class Args extends HashMap{
    public myMethod_1(){
        //...
    }
    public myMethod_2(){
        //...
    }
    public myMethod_3(){
        //...
    }
}

now,I want to get a Linked Args instance,but exnted LinkedHashMap,

I can't change Args exnteds to 开发者_运维问答LinkedHashMap,also can't change Args to a interfaces

can I get a linked Args instance ?

if not,how the best way to get a LinkedArgs? (not repeat myMethod_1-3)


The simple solution is change Args to extend LinkedHashMap. (I know you said you can't ...)

If that is not an option, then the next best solution is to change Args to implement Map and delegate all of the methods in the Map API (and others as required) to a private LinkedHashMap instance.

If that is not an option, you could do the same with extends HashMap. Basically, you override all of the methods in the parent HashMap, and delegate the actions to a private LinkedHashMap instance. (It is UGLY but it works ... modulo that each Args object has a bunch of attributes that are initialized and never used.)

0

精彩评论

暂无评论...
验证码 换一张
取 消