Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm a little confused with the naming conventions used in default functional interface names available in javax.util.function package:
For instance, primitive specialization of Function have names like:
IntFunction/LongFunction/DoubleFunction in which argument type is of specified type
But primitive specialization of Supplier have names like:
BooleanSupplier/DoubleSupplier/LongSupplier/IntSupplier in which return type is of specified type.
If you compare the name and functionality of other interfaces in java.util.function, shouldn't the names have been like:
ToBooleanSupplier/ToDoubleSupplier/ToLongSupplier/ToIntSupplier?
The word "to" in ToIntFunction, ToDoubleFunction, et al indicates that something is being converted to something else. The function's input parameters are being converted into an int/double/whatever.
The word "supplier" denotes a function that takes no input and returns some value. It supplies values. There's no input, only output.
Adding "to" would be redundant and/or misleading: redundant because the fact that it returns values is already indicated by the word "supplier"; misleading because there's no conversion. The values are generated out of thin air.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I understand the main difference between the two,
#RequestParam is used for query parameters, and can have few more attributes,
while #PathVariable has one attribute and is for a path parameter.
but I couldn't find any info about when there's a preference to use either query param or path param.
I assume that in some cases in which I want a default value or some other attribute that #RequestParam has, It's probably better to use it. but is there any big difference other than that? any time that #PathVariable is preferred?
It depends on your design choices, i.e. whether you want to have information in your path or the query part. Using REST you would normally put resource identifiers into the path and additional parameters into the query, e.g. like this (made up):
/questions/67156664/comments?count=5
This would mean:
comments for question with id 67156664 (path variable)
return up to 5 comments (query param)
Note again, that it often depends on your requirements, i.e. what part of your url you want to put the parameters in.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am making a GUI in Java, and I was wondering how do you add user inputs (integers) in a JTextField? If so, please post with some code so I can understand. (I am just a beginner programmer)
What all you need to do:
jTextField.setText(String.valueOf(intValue));
Because JTextField takes a String to set its value you have to convert the int to String.
See This for more details.
A JTextField contains text. You get this text using textField.getText(), which returns a String. This String might happen to represent a valid integer. If you want to get the value of the integer, you need to transform the String into an int. That's done using the Integer.parseInt() method:
int sum = Integer.parseInt(textField1.getText()) + Integer.parseInt(textField2.getText());
Of course, if one of the text fields contains text that doesn't represent an integer, you'll get an exception, as documented in the Integer.parseInt() javadoc.
Given your question, it seems you don't really understand basic notions such as types, and basic classes such as String and Integer. My advice would be to forget about Swing for the moment, and exercise with basic programs not involving any UI.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I encounter a problem that with Java, I have a map,such as map<K,V>, K and V can be arbitrary type, e.g int, Long, String, Time, etc.
After the map is serialized, can I get the length of K or the V? Can I write a common method to implement this idea? Something like:
public long getLength(object obj) {
//how to get the length of this obj, obj can be any type
}
How could do that?
Nope.
But you can approximate though, here's a nice article about a sizeof function.
The reason is that you can change the default binary serialization (which is kinda verbose). There are comparisons for these tools, the last time I was in this topic Kyro was the most optimal (10x smaller than the default Java binary serialization, because it does not neither export redundant nor anything verification-related data).
Here's a comparison about the tools.
There's no way to get the length of an object after serialization except by serializing it.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have to deal with a domain object that's real name is 351K-Report. According to the Java naming convention its forbidden to use a number at the beginning of an identifier.
I don't want to fully spell out the number. And, I also think that it's a bad idea to place an underline in front of the number.
But what is the recommended alternative?
UPDATE
There are also other reports, like SpecReport, TopReport, LF10Report and so on. So I'm very doubtful that inverting parts of the noun changes the meaning of the whole project.
Maybe reverse it. For example:
report351K
That would be very bad..
Imagine this:
int 1d = 3;
double d = 1d * 2;
What would be d?
Alternatives:
Since variables that begins with _ usually indicates for class member, I would use report351K.
if you really want to do this then _351KReport but I don't think you should do this. try to make something meaningful of it and at the same time is convineient to Java
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
We are writing a hierarchy of classes that implement various ways to represent languages. There is a base LanguageCode class with several subclasses, including ISO1LanguageCode for ISO 639-1 codes (example: 'en'), ISO2LanguageCode for ISO 639-2 codes (example: 'eng'), and HumanReadableLanguageCode (example: 'English'). At any time, we need to be able to convert between any two of the subclasses. Is there some design pattern magic we could use here to help?
Note:
Our first idea was to standardize the base class and make each subclass write a conversion routine between itself and the standard on the base class. That way, to convert between ISO2LanguageCode and HumanReadableLanguageCode, use LanguageCode as a bridge.
There is only one set of languages. Each language has an -1 code, a useless -2 code, and a -3 code. And a human-readable name. So make one enum with accessors to return the different codes, and multiple lookup static methods.