肉松饼罗曼史
2017-03-13 08:12
采纳率: 21.1%
浏览 2.1k
已采纳

java枚举类型的构造方法处理

我知道构造函数怎么写,但是枚举类型,枚举其他的对象,这里应该怎么添加呢?能不能给我以id为例,进行枚举的构造方法添加啊?不胜感激啊
package com.java;

public class Locator {
private String element;

private int waitSec;

public enum ByType {
    xpath, id, linkText, name, className, cssSelector, partialLinkText, tagName
}

private ByType byType;

public Locator() {

}


public Locator(String element) {
    this.element = element;
    this.waitSec = 3;
    this.byType = ByType.xpath;

}

public Locator(String element, int waitSec) {
    this.waitSec = waitSec;
    this.element = element;
    this.byType = ByType.xpath;

}



public Locator(String element, int waitSec, ByType byType) {
    this.waitSec = waitSec;
    this.element = element;
    this.byType = byType;
}

public String getElement() {
    return element;
}

public int getWaitSec() {
    return waitSec;
}

public ByType getBy() {
    return byType;
}

public void setBy(ByType byType) {
    this.byType = byType;
}

public void setReplace(String rep, String rex)
{
    StringTools.replaceAll(element, rex, rep);
}

}

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 夕阳雨晴 2017-03-13 08:21
    已采纳

    public enum ByType {
    xpath, linkText, name, className, cssSelector, partialLinkText, tagName
    private String id;
    public ByType(String id){
    this.id=id;
    }
    }

    可以参考这篇文章。http://blog.csdn.net/vvhesj/article/details/45394587

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题