Hey fellas, long time PHP programmer (yes you can roll your eyes) trying to do Java. Although I initially came from C++ and Java programming to PHP, I'm having trouble grasping a concept:
I'm creating a jdbm hash table and putting in a String[] as the value, but when I try to get() it, it returns type Object and does not like being casted back to String[]. What is going on and why not?
I've tried putting (String[]) explicit cast in front of the get, but still errors as saying:
java.lang.Strin g cannot be cast to [Ljava.lang.Stri ng
---------------------------------------------
FIXED before I finished my post, for anyone else who has the same issue. Experts, comments/feedback are welcome.
Explanation of my bug:
I was using an existing jdbm file that already had these keys with String values, not an array. recreated it and then the explicit casting worked. But I didn't use String[] anymore I used java.util.HashS et because my lists could get pretty large.
Thanks,
Dan
I'm creating a jdbm hash table and putting in a String[] as the value, but when I try to get() it, it returns type Object and does not like being casted back to String[]. What is going on and why not?
Code:
hashtable = HTree.createInstance( recman );
.
.
.
String[] test= {"test hard, testhard2", "romeo must test", "live rich or test trying"};
String[] romeo = {"romeo must die","romeo and juliet","romeo and juliet 2"};
hashtable.put( "die", die );
hashtable.put( "die", romeo );
.
.
.
// Error Line:
String[] titleArr = hashtable.get("die");
Error: Uncompilable source code - incompatible types
java.lang.Strin g cannot be cast to [Ljava.lang.Stri ng
---------------------------------------------
FIXED before I finished my post, for anyone else who has the same issue. Experts, comments/feedback are welcome.
Explanation of my bug:
I was using an existing jdbm file that already had these keys with String values, not an array. recreated it and then the explicit casting worked. But I didn't use String[] anymore I used java.util.HashS et because my lists could get pretty large.
Thanks,
Dan
Comment