-3

The following java code, which outputs false:

class Value {
int i;
}
public class EqualsMethod2 {
public static void main(String[] args) {
Value v1 = new Value();
Value v2 = new Value();
v1.i = v2.i = 100;
System.out.println(v1.equals(v2));
}
} 

Why isn't the result true instead? While reading some Java documentation I've found the following answer: the default behavior of equals() is to compare handles. But aren't v1 and v2 handles?

Thank you in advance.

4

2 回答 2

1

只是setInterval用来定期检查你需要什么

<html>
    <head>
       <script type="text/javascript">
           var myInterval,
           myColorName,
           myDelay = xxx;
           function onLoad(){
               startTimer();  
           }
           function startTimer(){
               myInterval  = setInterval(function(){
                   myColorName = document.forms['form1'].elements['textbox'].value;
                   if(myColorName.length>0){
                       //do what you want with your color        
                   }
               },myDelay);
           }
           function stopTimer(){
               clearInterval(myInterval);
           }
       </script>
    </head>
    <body onload="onLoad()">
        <form name="form1">
            <fieldset>
            <legend>Enter Color Name:</legend>
            <input type="text" name="textbox"/>
            </fieldset>
        </form>
    </body>
</html>
于 2013-03-24T11:25:06.463 回答
0

不要尝试定期获取值,因为在输入中键入数据时,您将无法立即获取数据。

尝试<input type=¨text¨ name=¨some¨ onkeyup=¨typed(this.value)¨/>

function typed(value)
{
console.log(value);
}
于 2013-03-24T11:24:06.200 回答