현재 Processing 3에서 작업 중이며 HashMap의 반환을 이해하는 데 문제가 있습니다. 나는지도, 내 클래스를 사용 Map<String, Chromosome> genes = new HashMap<String, Chromosome>()
을 가지고HashMap get() return 메서드에서 받기
class Chromosome{
Genotype geneOne;
Genotype geneTwo;
Chromosome(){ ... }
Chromosome(Genotype gOne, Genotype gTwo){ ... }
void setGeneOne(Genotype gene){ ... }
void setGeneTwo(Genotype gene){ ... }
Genotype getDomGene(){ ... }
Genotype getRecGene(){ ... }
}
class Genotype{
Object value;
float weight;
public Genotype(int value, float weight){ ... }
public Genotype(int[] value, float weight){ ... }
public Genotype(String value, float weight){ ... }
public Genotype(float value, float weight){ ... }
public Object getValue(){ ... }
public float getWeight(){ ... }
public void setValue(int value){ ... }
public void setValue(int[] value){ ... }
public void setValue(String value){ ... }
public void setValue(float value){ ... }
}
내가 생각하고있어 내가지도에서 값을 "얻을"때, 나는 거기에서 메서드에 액세스 할 수 있어야한다는 것입니다. I.E.
class Flower{
Map<String, Chromosome> genes;
Flower(){
genes = new HashMap<String, Chromosome>();
genes.put("color", new Chromosome(new Genotype(64, 1.0), new Genotype(25,0.5)));
Genotype test = genes.get("color").getDomGene(); //should return the first param passed to the new chromosome
}
}
나는 그것을 사용할 때마다 반환 된 객체를 선언 할 필요가 없길 바랍니다. 20 분의 인터넷 검색 결과에서이 작업에 대해 아무 것도 찾을 수없는 것 같습니다. 왜이 기능이 작동하지 않으며 그 문제를 해결하려면 무엇을 할 수 있습니까?
는 [mcve]을 제공하십시오를 같은 패키지의 모든 클래스를 넣어 시도하거나 확인 . – shmosel
귀하의 질문은 무엇입니까? "Processing 3"이란 무엇을 의미합니까? –
@AriaPahlavan [Processing] (https://processing.org/)은 Java의 일부라고 할 수 있습니다. 내 질문은 게시물 하단에 분명히 표시되어 있습니다. –