我在JAVA编写程序,我正在使用HashMap。
$ ~/.local/bin/spyder3
Failed to write user configuration file.
Please submit a bug report.
Traceback (most recent call last):
File "/home/stelios/.local/lib/python3.6/site-packages/spyder/utils/external/lockfile.py", line 150, in lock
symlink(str(os.getpid()), self.name)
FileExistsError: [Errno 17] File exists: '9449' -> '/home/stelios/.config/spyder-py3/spyder.lock'
Plane是我创建的一个类:
private HashMap<Integer,Plane> planes;
然后我尝试打印HashMap的所有组件:
public class Plane {
private int planeNumber;
private int departureTime;
private int arrivalTime;
private int flightDuration;
private int aerialDrops;
//constructors...
}
问题是我想打印描述平面的所有变量的值,而是从mentry.getValue()获得aircrafts.Plane@15db9742。我该如何解决这个问题?
答案 0 :(得分:3)
您需要为 Plane 类覆盖并添加 toString 方法,
gender = input("What is your gender? ")
if 'male' == gender:
print("You are a boy!")
if 'female' == gender:
print("You are a girl!")
现在你正在使用Object类parent
的toString方法答案 1 :(得分:0)
根据您的需要,稍作改动可以正常工作:
public class Plane {
private int planeNumber;
private int planeNumber;
private int arrivalTime;
private int flightDuration;
private int aerialDrops;
public String toString()
{
return planeNumber +" "+planeNumber+" "+arrivalTime+" "+flightDuration+" "+aerialDrops
}
}