小编Tum*_*Tum的帖子

对于良好的编码实践,如果我们已经在method1和method1中验证了这些数据到method2,我们是否还必须在method2中再次验证数据?

我想说

public void method1(){
    String s1="";
    String s1=getText();
    if(MyValidation.isOk(s1)){
       dosomethingWith s1 here
       then
       method2(s1);
    }
}

public void method1(String s1){
    if(MyValidation.isOk(s1)){ // do we need this line of code??
        //do something
    }
}
Run Code Online (Sandbox Code Playgroud)

对于良好的编码实践,

如果我们已经在method1中验证了它并且method1将该数据传递给method2,我们是否还必须在method2中再次验证数据?

php c# c++ java validation

0
推荐指数
1
解决办法
82
查看次数

对于Server包中的类来说,访问GWT中的Client包中的方法是否安全?

好的,我是uisng GWTP,它有客户端,服务器和共享包.

我在客户端有一个Util类.

my.client.Util.java{
  public static String method1();
  //more methods here
}
Run Code Online (Sandbox Code Playgroud)

在服务器我有

my.server.GetDataActionHandler{
    ///Should I do like this
    String s=my.client.Util.method1();
}
Run Code Online (Sandbox Code Playgroud)

这样做是否安全,或者我应该将Util放入共享包中,就像这样

my.shared.Util.java{
  public static String method1();
  //more methods here
}
Run Code Online (Sandbox Code Playgroud)

如果我们将Util放在共享包中有什么不同?是安全还是其他任何好的理由?

gwt gwtp

0
推荐指数
1
解决办法
108
查看次数

给定2个对象:myPanel1和myPanel2,如果我们多次将myPanel2添加到myPanel1中,那么为什么myPanel1.getWidgetCount()仍然= 1;

这段代码在Gwt中,但如果您只是了解Java,那么您仍然可以回答这个问题.

好的,我有2个面板:myPanel1和myPanel2,然后我多次将myPanel2添加到myPanel1

myPanel1.add(myPanel2);
myPanel1.add(myPanel2);
myPanel1.add(myPanel2);
myPanel1.add(myPanel2);
....
Run Code Online (Sandbox Code Playgroud)

然后我计算小部件的数量 myPanel1

System.out.println("No of Widgets inside myPanel1: "+ myPanel1.getWidgetCount());
Run Code Online (Sandbox Code Playgroud)

结果是" No of Widgets inside myPanel1: 1"

为什么myPanel1中的Widgets数量仍为1,即使我们多次将myPanel2添加到myPanel1中?

java gwt

0
推荐指数
1
解决办法
50
查看次数

什么是Java Regex检查"= 2245"或"= 545"或"= 22"等?

好吧,我想检查一个字符串是否有=第一个字符,然后是任何数字,如果=&number 之间有空格那么也可以.

好的,这是一个例子,

String s="=2245"; --> return true
String s="=   545"; --> return true
String s="= 22"; --> return true
String s="= m  545"; --> return false
String s="=m545"; --> return false
Run Code Online (Sandbox Code Playgroud)

这就是我所做的

if(s.matches("=[0-9]+")){
   return true;
}
Run Code Online (Sandbox Code Playgroud)

如果=&number 之间没有空格,这将有效

所以我改为:

if(s.matches("=\\s[0-9]+")){
       return true;
}
Run Code Online (Sandbox Code Playgroud)

然后,如果=&号码之间有1个空格,则它将起作用,而在其他情况下则不起作用.

那么如何解决呢?

java regex

0
推荐指数
1
解决办法
51
查看次数

正则表达式,用于检查String是否为正自然数

我想检查字符串是否为正数,但我不想使用,Integer.parseInt()因为用户可能输入的数字大于int.相反,如果数字字符串包含所有"0"字符,我宁愿使用正则表达式返回false.

if(val.matches("[0-9]+")){
    // We know that it will be a number, but what if it is "000"?
    // what should I change to make sure 
    // "At Least 1 character in the String is from 1-9"
}
Run Code Online (Sandbox Code Playgroud)

注意:字符串必须只包含0- 9并且它不能包含所有0s; 换句话说,它必须至少有1个字符[1-9].

java regex

0
推荐指数
1
解决办法
2076
查看次数

copyList(List <T> destinationList,List <T> sourceList),为什么Eclipse不识别泛型T?

我有一个copyList(List<T> destinationList, List<T> sourceList)T泛型类型的方法.这意味着sys只接受如果destinationList和sourceList具有相同的类型,如果它们没有,那么该方法将不允许.

例如:copyList(List<String[]> destinationList, List<String[]> sourceList或被copyList(List<String[][]> destinationList, List<String[][]> sourceList允许

copyList(List<String[][]> destinationList, List<String[]> sourceList不允许因为他们没有相同的类型.

但是,我的eclipse有这个错误"T无法解析为一个类型"

java generics

-1
推荐指数
1
解决办法
68
查看次数

什么是红色的安全HTML颜色代码,从温和的红色到非常红色?(HTML)

我正在开发一个国际象棋程序,在这个程序中它会显示一点点红色用于微弱的移动和较暗的红色用于非常弱的移动.

我需要5级红色代码,从轻微到非常红.

#ff0000
Run Code Online (Sandbox Code Playgroud)

是一个,那么你可以建议我一些.

注意:它必须适用于所有浏览器.

html javascript css

-1
推荐指数
1
解决办法
237
查看次数

标签 统计

java ×5

gwt ×2

regex ×2

c# ×1

c++ ×1

css ×1

generics ×1

gwtp ×1

html ×1

javascript ×1

php ×1

validation ×1