Answer the question
In order to leave comments, you need to log in
How to pass an argument of type Map to a method?
First of all I create a Person class to hold some information
public class Person {
private String name, surname;
public Person (String name, String surname){
this.name = name;
this.surname = surname;
}
public String toString (){
return "Person: " + surname + " " + name;
}
}
public class Data {
// Class of Car
public class Car extends Data {
private String Mark;
public Car (String Mark){
this.Mark = Mark;
}
public String toString (){
return "Car: " + Mark;
}
}
// Class of House
public class House extends Data {
private String Adress;
public House (String Adress){
this.Adress = Adress;
}
public String toString (){
return "House: " + Adress;
}
}
// Class of Work
public class Work extends Data {
private String Work;
public Work (String Work){
this.Work = Work;
}
public String toString (){
return "Work: " + Work;
}
}
}
public class MainClass {
// Массив Map
public static Map <Person, List <? extends Data>> info =
new HashMap <Person, List <? extends Data>> ();
// Вывод информации
public static void ShowInfo (){
for (Person person : info.keySet()){
System.out.println (person);
for (Data e : info.get(person)){
System.out.println(e);
}
}
}
// Как ставить аргумент типа Arrays.asList ();???
public static void addPerson (Person person){
}
public static void main(String[] args) {
// Как передать этот участок кода как аргумент методу?
info.put(new Person ("Nikolay", "Nikolaev"),
Arrays.asList(
new Data().new Car ("Jiguli"),
new Data().new House ("Muhosransk"),
new Data().new Work ("alcogolic")));
ShowInfo ();
}
}
info.put(new Person ("Nikolay", "Nikolaev"),
Arrays.asList(
new Data().new Car("Jiguli"),
new Data().new House("Muhosransk"),
new Data() .new Work("alcogolic")));
// How to put an argument like Arrays.asList ();???
public static void addPerson (Person person){
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question