你如何製作變量班級?這個詞是什麼意思?我被告知爲了在不同的類中使用字符串全名,我需要創建變量類級別並添加getter方法?任何人都可以解釋這個概念是什麼意思,以及如何正確完成?下面列出了相關課程的代碼。你如何製作一個可變的課程級別?
public class SaxHandler extends DefaultHandler {
private String artifactIdTag = "close";
private String versionTag = "close";
private String fullname;
public String getFullname() {
return fullname;
}
private boolean inDependency=false;
private boolean inProperties= false;
public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {
if (qName.equalsIgnoreCase("properties")) {
inProperties = true;
}
if (qName.equalsIgnoreCase("artifactId")) {
artifactIdTag = "open";
}
if (qName.equalsIgnoreCase("version")) {
versionTag = "open";
}
if (qName.equalsIgnoreCase("dependency")) {
inDependency=true;
}
if (inProperties) {
System.out.println("startElement property");
}
}
private String artifact=null;
private String version=null;
public void characters(char ch[], int start, int length)
throws SAXException {
if (inProperties) {
artifact = new String(ch, start, length);
System.out.println("property characters: "+artifact);
}
if (artifactIdTag.equals("open")) {
artifact = new String(ch, start, length);
version=null;
artifact = artifact.replace("-${org.springframework.version}", "");
System.out.print("artifactId: " + artifact);
}
if (versionTag.equals("open")) {
version = new String(ch, start, length) + ".jar";
version = version.replace("-${org.springframework.version}", "");
String fullname=artifact +"-" +version;
if (inDependency && !(artifact == null || version == null)){
fullname = fullname.replace("-${org.springframework.version}", "");
fullname = fullname.replace("-${spring.security.version}", "");
System.out.printf("%-15s %n", fullname);
FileNameStorage.add(fullname);
}
}
}
public void endElement(String uri, String localName,
String qName) throws SAXException {
if (qName.equalsIgnoreCase("artifactid")) {
artifactIdTag = "close";
}
if (qName.equalsIgnoreCase("version")) {
versionTag = "close";
}
if (qName.equalsIgnoreCase("dependency")) {
inDependency=false;
}
if (qName.equalsIgnoreCase("properties")) {
inProperties = false;
}
}
}
你寫這個了嗎? –