Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 What errors be in this code, please help me~
SNIX





发贴: 43
积分: 30
于 2007-03-18 20:42 user profilesend a private message to usersend email to SNIXsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

public class Example_014 {

class Person{
String name;
int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
// example start
public String toString() {
return new String(name + ":" + age);
}
// fixed code
public String toString2() {
return name + ":" + age;
}
// example end
}
// test start
public static void main(String[] args) {
Example_014 test = new Example_014();
test.time(100000, false); // to warm up jvm
test.time(100000, true);
}
boolean print = false;
private long stamp;
private void time(int n, boolean p) {
print = p;
start();
Person bob = new Person("bob", 18);
for (int i = 0; i < n; i++) {
bob.toString();
}
time("with extra constructor");
for (int i = 0; i < n; i++) {
bob.toString2();
}
time("fixed");
}
private void start() {
stamp = System.currentTimeMillis();
}
private void time(String m) {
long a1 = System.currentTimeMillis() - stamp;
if (print) {
System.out.println(a1 + " ms for " + m);
}
System.gc();
start();
}



{ Show us the error message, please.}


why edited on 2007-03-19 17:47


话题树型展开
人气 标题 作者 字数 发贴时间
10670 What errors be in this code, please help me~ SNIX 1284 2007-03-18 20:42
8786 Re:What errors be in this code, please help me~ SNIX 203 2007-04-02 23:20
8250 Re:What errors be in this code, please help me~ redcolor 111 2007-04-03 17:56
8128 Re:What errors be in this code, please help me~ cxp108 171 2007-04-03 21:08
8616 Re:What errors be in this code, please help me~ JiafanZhou 103 2007-04-04 00:48

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923