Search found 215 matches

by ImLazy
Fri May 26, 2006 4:07 pm
Forum: Java
Topic: Why does this code get warning?
Replies: 10
Views: 5640

Thank you.
Anyway, I use the second code.
by ImLazy
Fri May 26, 2006 3:09 am
Forum: Java
Topic: Why does this code get warning?
Replies: 10
Views: 5640

Do you mean Vector.clone() is an overriden method, so I can't change the type? But why is the first code compiled OK?
by ImLazy
Fri May 26, 2006 12:18 am
Forum: Java
Topic: Why does this code get warning?
Replies: 10
Views: 5640

Sorry, I don't quite understand.
by ImLazy
Thu May 25, 2006 10:58 am
Forum: Java
Topic: Why does this code get warning?
Replies: 10
Views: 5640

The compiler says the type of "(Vector<String>)(v1.clone())" is Object but not Vector<String>.
Why?
by ImLazy
Thu May 25, 2006 9:10 am
Forum: Java
Topic: Why does this code get warning?
Replies: 10
Views: 5640

Why does this code get warning?

This code is compiled OK. import java.util.Vector; public class Ve { public static void main(String[] args) { Vector v1 = new Vector(); Vector v2 = (Vector)(v1.clone()); } } But if I substitute all the "Vector" by "Vector<String>": import java.util.Vector; public class Ve { public static void main(S...
by ImLazy
Sat May 06, 2006 4:55 am
Forum: Java
Topic: Why this compile error?
Replies: 6
Views: 4634

Cool code! That's just what I want.
Sorry, I didn't know "static" can be used in this way.
Thank you very much.
by ImLazy
Fri May 05, 2006 9:30 am
Forum: Java
Topic: Why this compile error?
Replies: 6
Views: 4634

I think pure TreeSet is not suitable here, because I want to provide a static method "isKeyword()" which needs a static TreeSet. But where can I insert elements into the TreeSet? I must override the constructor of TreeSet. So I wrote a class to inherit it.
by ImLazy
Fri May 05, 2006 1:25 am
Forum: Java
Topic: Why this compile error?
Replies: 6
Views: 4634

In fact, this is my true code: import java.util.TreeSet; public class Base { private static class KeywordSet extends TreeSet<String> { public KeywordSet() { super(); super.add("for"); super.add("while"); super.add("switch"); super.add("class"); //etc. } } private static KeywordSet keywords = new Key...
by ImLazy
Thu May 04, 2006 4:45 pm
Forum: Java
Topic: Why this compile error?
Replies: 6
Views: 4634

Why this compile error?

Code: Select all

public class Test {
    private class A {
        public int i;
        public A() {
            i = 0;
        }
    }

    private static A x = new A();
}
When the field x is not static, it is compiled O.K. But I want the field x to be "private static". How should I deal with it?
by ImLazy
Tue Apr 25, 2006 2:40 am
Forum: Java
Topic: Why this code gets a warning?
Replies: 2
Views: 3011

Thank you.

BTW, the add() method thorws "ClassCastException". Of course we usually need not to catch it. But because I get warning, I just want to tell the compiler I do everything safely. Now I have deleted the "try" and "catch".
by ImLazy
Tue Apr 25, 2006 12:43 am
Forum: Java
Topic: Why this code gets a warning?
Replies: 2
Views: 3011

Why this code gets a warning?

Code: Select all

import java.util.*;
public class Base {
    private TreeSet set;
    public Base() {
        set = new TreeSet<String>();
        try {
            set.add("abc");
        } catch (Exception e) {}
    }
}
I compiled it by jdk1.5.0_06.
by ImLazy
Tue Apr 18, 2006 2:50 pm
Forum: C++
Topic: Does the program become slow if I define variable in a loop?
Replies: 3
Views: 1727

Does the program become slow if I define variable in a loop?

For example, this code:

Code: Select all

for (int i = 0; i < 100; i++) {
    int a = i;
    f(a);
}
Will the variable "a" be allocated 100 times? Or it is allocated at the beginning of the loop and destroyed when the loop finishes?
by ImLazy
Thu Apr 13, 2006 4:34 pm
Forum: C++
Topic: how to output binary numbers by "cout"?
Replies: 5
Views: 4562

Oh, I see. Thank you for your help and also for your telling me a good website.
by ImLazy
Tue Apr 11, 2006 3:39 am
Forum: C++
Topic: how to output binary numbers by "cout"?
Replies: 5
Views: 4562

Oh, I see.
Thanks.

Another question. This code:

Code: Select all

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int a = 1234;
    cout.setf(ios::hex);
    cout << a << endl;
    cout << hex << a << endl;
    return 0;
}
why the output is

Code: Select all

1234
4d2
by ImLazy
Mon Apr 10, 2006 1:47 pm
Forum: C++
Topic: how to output binary numbers by "cout"?
Replies: 5
Views: 4562

how to output binary numbers by "cout"?

I use this code, but failed.

Code: Select all

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int a = 1234;
    cout << setbase(2) << a << endl;
    return 0;
}
The output is still "1234".
Help.

Go to advanced search