In java is there any way to use AND instead of &&
I just want to know t开发者_运维技巧hat is it possible in java to use
class{
private final static String AND="&&";
public static void main(String...args)
{
String str="subodh";
if(str!=null AND str.equals("subodh") )
{
System.out.println(str);
}
}
}
The above is not allowed but is there any such kind of way through we can use it by putting some extra efforts if it's please let me know or please put your openions. Thanks
No, there's no way of changing the operators in Java - thankfully, IMO.
I suggest you learn to use Java as Java rather than trying to make it look like some other language. (Or use that other language which looks more like you want it to.)
If you're trying to do something other than bend the language to your personal preferences, please edit the question to explain what your purpose is.
No, There is no any way to use this. For that I have to go through different language.
No way to make this possible. && is operator and you cannot assign an operator to a String variable. Here AND acts like a String variable.I hope you will get it.I also do not think one will need anything like this in any situation. If possible make your motive clear why you want to this?
If you really wanted to you can implement a class to "prettify" logical operations using method chaining . And then use it something like:
PrettifyLogic.condition(str!=null).and(str.equals("subodh")).evaluate();
Though I don't personally find that more appealing to read/write. Also, good luck with operator precedence if you try something like this!
Nope, Java doesn't support doing this type of thing and I'm thankful for that! If it did we could get all sorts of things meaning && which would make existing code hard to read.
If you want to code in Java, you'll just have to stick with the way Java does things.
精彩评论