我知道在抽象类中,方法既可以是抽象的,也可以不是抽象的.但为什么我不能在"普通"非抽象类中创建抽象方法呢?
在此先感谢任何解释!
我在表单中有几个数组:
private static String[] patientNames = { "John Lennon", "Paul McCartney", "George Harrison", "Ringo Starr" };
Run Code Online (Sandbox Code Playgroud)
然后我像这样制作一个TreeSet:
TreeSet<Patient> patTreeSet = new TreeSet<Patient>();
Run Code Online (Sandbox Code Playgroud)
患者是另一类产生"患者"对象的人.然后我遍历我的数组中的每个元素来创建几个患者并将它们添加到我的patTreeSet喜欢这样:
for(int i = 0; i< patientNames.length; i++){
Date dob = date.getDate("MM/dd/yyyy", patientBirthDates[i]);
Patient p = new PatientImpl(patientNames[i], patientSSN[i], dob);
patTreeSet.add(p);
}
Run Code Online (Sandbox Code Playgroud)
但是当我去检查我的patTreeSet.size()时候它只返回"1" - 这是为什么?
我知道我的对象运行良好,因为当我尝试做同样的事情,但ArrayList相反,一切正常.所以我猜我正在使用TreeSet错误.
如果有帮助,Patient会有一个名为getFirstName()的方法,当我尝试执行以下操作时:
Iterator<Patient> patItr = patTreeSet.iterator();
while(patItr.hasNext()){
System.out.println(patItr.next().getFirstName());
}
Run Code Online (Sandbox Code Playgroud)
然后只有"John"打印,显然不应该这样......所以,我是否完全滥用TreeSet?
在此先感谢您的帮助!
编辑如下
================ PatientImpl Class ====================
public class PatientImpl implements Patient, Comparable{
Calendar cal = new …Run Code Online (Sandbox Code Playgroud) 我刚刚学习了一些Swift,我遇到了关于嵌套函数的部分:
函数可以嵌套.嵌套函数可以访问外部函数中声明的变量.您可以使用嵌套函数来组织长或复杂函数中的代码.
从这里开始
因此,如果声称的好处是"组织代码",为什么不在外部函数之外独立地拥有嵌套函数?对我来说,这看起来更有条理.
我能辨别的唯一好处是你"可以访问在外部函数中声明的变量",但与嵌套函数的混乱相比,这似乎微不足道.
有什么想法吗?
conventions function code-organization nested-function swift
以前是:
class App extends Components{
//...
}
Run Code Online (Sandbox Code Playgroud)
现在create-react-app在App.js:
function App(){
//...
}
Run Code Online (Sandbox Code Playgroud)
有人知道为什么要进行此更改吗?他们是否暗示我们不应该在App中拥有状态?
我有一个带有列表的XML文件,其中每个元素只有一个属性,我试图删除一个特定的元素,但它不起作用.我的删除Java代码是:
SAXBuilder builder = new SAXBuilder();
Document readDoc;
try {
readDoc = builder.build(new File(INACTIVE_FILE));
List<Element> inactiveDocList = readDoc.getRootElement().getChild("inactiveDoctorList").getChildren();
for(Element e: inactiveDocList){
if(e.getAttributeValue("inactiveDoctorID").equals("1")){
e.removeContent();
}
}
XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat());
xmlOutput.output(readDoc.getRootElement(), new FileOutputStream(new File(INACTIVE_FILE)));
}
catch (JDOMException | IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我的XML是:
<root>
<inactiveDoctorList>
<doctor inactiveDoctorID="1" />
<doctor inactiveDoctorID="2" />
<doctor inactiveDoctorID="4" />
<doctor inactiveDoctorID="16" />
<doctor inactiveDoctorID="3" />
<doctor inactiveDoctorID="9" />
<doctor inactiveDoctorID="13" />
<doctor inactiveDoctorID="14" />
<doctor inactiveDoctorID="11" />
<doctor inactiveDoctorID="6" />
</inactiveDoctorList>
</root>
Run Code Online (Sandbox Code Playgroud)
当我执行e.removeContent()或e.removeChild("doctor")时没有任何反应,当我尝试e.detach()时,我收到此错误:
Exception …Run Code Online (Sandbox Code Playgroud) java ×3
abstract ×1
conventions ×1
function ×1
reactjs ×1
removechild ×1
set ×1
swift ×1
treeset ×1
xml ×1