-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anonymous class as a custom tuple #102
Comments
Jinq is normal Java code. Java does not support duck typing or other features needed to get your suggested syntax to work, so Jinq cannot support such functionality. |
import java.util.function.*;
public class MyClass {
public static void main(String args[]) {
var a = new A<Integer>();
var b = a.map(x -> new Object() { int v = x; })
.map(o -> new Object() { String s = Integer.toString(o.v); });
}
}
class A<T> {
public <R> A<R> map(Function<T, R> f) { return new A<R>(); }
} This is compilable with Java 10+ UPD: A<Integer> a = new A<Integer>();
A<String> b = a.map(x -> new Object() { int v = x; })
.map(o -> new Object() { String s = Integer.toString(o.v); })
.map(o -> o.s); |
Okay, that’s good to know. I’ll keep it in mind as a possible future feature. It would require writing a bunch of new analysis code for classes to see if they satisfy the usage patterns that you’ve shown. I’ve been thinking about how the framework could be modified to handle stuff like that before. Unfortunately, to be honest, I haven’t had the cycles available to add major features to Jinq in several years, so I probably won’t be able to get to it. |
Jinq has a potential to be the best (the only really good) Java ORM. Why it's not super-popular? 😄 |
Writing database queries in Java/C#/etc just generally stopped being popular. Microsoft doesn’t even push LINQ that much even more. Using LINQ or Jinq skillfully requires programmers to understand SQL anyway, so it’s probably easier to just work with a SQL-like language entirely instead of forcing programmers to learn an entirely different query language. Also, the technology behind Jinq is obscure, so I’m basically the only person who can code it up right now. The big software vendors don’t have the expertise to add Jinq-like functionality to their own ORMs, so they have no reason to promote such technology. Without strong demand, there’s no reason for the big software vendors to train up someone with the required compiler/VM/database/symbolic-execution expertise. Right now, the big software vendors are more interested in pushing NoSQL and AI and big data and stuff. |
@my2iu I like jinq very much, it's amazing, Thank you and all the developers. For mysql and h2, it works very well. |
It would be great to have this feature
Type inference with
var
is only allowed for local variables (they could allow that for fields in anonymous classes which are fully local but they didn't...) so you will need to explicitly specify the field types. But it still could be useful making the code more readable than with getOne()/getTwo(). And it would allow you to avoid creating separate custom tuple classes.The text was updated successfully, but these errors were encountered: