combining closures (FCM) and generics, would it be possible to have fully type-safe criteria.
// The following works without a cast as Foo.id is a 'long' field.
List<Long> ids = session.createCriteria(Foo.class)
.setProjection(Foo#id)
.list();
// The following is a compilation error, as F...
In the following scenario, I was trying to see how to handle this code and it how it relates to Runtimexception. I have read that is generally better to throw runtime exceptions as opposed to rely on static exceptions. And maybe even better to catch a static checked exception and throw an unchecked exception.
Are there any scenarios w...
For some reason, I'm getting an UnsupportedOpeationException with the following code. Examining it in the debugger, it looks like the object I'm calling remove() on is a list.
// to optimize, remove totalSize. After taking an item from lowest, if lowest is empty, remove it from `lists`
// lists are sorted to begin with
public static <T ...
Hi all. I am implementing a sort of ORM in Java. I am trying to do a static find method that is only in the parent class. Let me get to the point:
public class DB {
public static Object find (int id) {
// i want to return anew instance of the calling subclass
}
}
public class Item extends DB {
// nothing here
}
public class ...
I'm working on a Java project for class that stores workout information in a flat file. Each file will have the information for one exercise (BenchPress.data) that holds the time (milliseconds since epoch), weight and repetitions.
Example:
1258355921365:245:12
1258355921365:245:10
1258355921365:245:8
What's the most efficient way t...
I've got the following:
public abstract class Foo<T>{
//contents of Foo //
...
public class Bar<Q> extends Foo<T>{
//contents of Foo.Bar //
...
}
}
Later, in another class and java file, I am trying to construct an instance of the inner Bar class above, using the outer abstract class as a supertype. ...
I can compile this JNA example code (from step 2 of https://jna.dev.java.net/#getting_started):
package com.sun.jna.examples;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
/** Simple example of JNA interface mapping and usage. */
public class HelloWorld {
// This is the standard, stable way o...
I know something like this has been asked before, but the answer was sort of side tracked.
I want to develop a hash function which will take a word and spit out an address of an array.
So, for example, if you input god:
sort the word, d o g
perform some sort of function on this to get an address d o g -> some number
insert 'dog' into...
using binarySearch never returns the right index =/
int j = Arrays.binarySearch(keys,key);
where keys is type String[] and key is type String
I read something about needing to sort the Array but how do I even do that if that is the case?
I wish #java was smarter =/ <-- read:simpler
Given all this I really just need to know:
How d...
Ok, this question is best explained in code. So will try to present the most succinct example I can.
Timestamped.java
@Embeddable
public class Timestamped<E> {
private E value;
private Date timestamp;
...
}
Foo.java
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE")
public class...
What's the best/easiest way to generate *.hbm.xml files from pojos?
...
I have a jar file with several classes which have static main methods. Can I execute them inside the jar from the command line? If not, can I execute them one by one?
...
I tried the jnaerator SimpleMeaningfulExample
(http://code.google.com/p/jnaerator/wiki/SimpleMeaningfulExample) and
got:
$ java -jar jnaerator-0.9.2.jar -library Test Test.h -o . -v
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad
version number in .class file
at java.lang.ClassLoader.defineClass1(Native Me...
Hi,
This is a more specific question to follow up on another question that I have asked recently. A correct answer for this question will earn a correct answer for that previous question too (since that is still in limbo)!
Basically I have a Java desktop application with a memory leak issue. I am using the memory profiler in Netbeans I...
I want to merge sorted lists into a single list. How is this solution? I believe it runs in O(n) time. Any glaring flaws, inefficiencies, or stylistic issues?
I don't really like the idiom of setting a flag for "this is the first iteration" and using it to make sure "lowest" has a default value. Is there a better way around that?
publi...
I wrote a class that has a map of <String, Object>. I need it to hold arbitrary objects, but at the same time sometimes I need to cast some of those objects, so I'll do something like
HashMap<String, Object> map = new HashMap<String, Object>();
Object foo =...
I am trying to publish an Atom/RSS feed in my Java based Google App Engine code. I have tried using Rome and keep getting the following error (tried googling without success), also the code I am running that generates the error is the demo code (so I get the feeling Rome won't work with GAE)
java.lang.NoClassDefFoundError: org/jdom/JDOM...
Has anyone has ever seen an implementation of java.nio.ByteBuffer that will grow dynamically if a putX() call overruns the capacity?
The reason I want to do it this way is twofold:
1) I don't know how much space I need ahead of time.
2) I'd rather not do a new ByteBuffer.allocate() then a bulk put() every time I run out of space.
I co...
I'v been playing with java applets recently. In the one im writing now I have a static nested class. It works fine in the viewer, but when I compile it I get 2 class files. classname.class and classname$nestedclassname.class. I've never encountered anything like this (started java a week ago) and I don't how I would jar/sign them. Also, ...
Hi, I have to create a method find that would use a local Set to collect the objects and the root. Then, I would compress the object e (in the parameter) and have the roost as its parent. Then, I would return the reference to the root. I can use the Graph, Map, and set class since it was imported. But, how can I call the parent of the ro...