Can I multiply an int with a boolean in C++?

This is technically fine, if a bit unclear. The bool will be promoted to an int, so the result is well-defined. However, looking at that code I don’t instantly get the semantics you are trying to achieve. I would simply write something like: height = legendText->isEmpty() ? 0 : height; This makes your intent far … Read more

Is it ok to read a shared boolean flag without locking it when another thread may set it (at most once)?

It is never OK to read something possibly modified in a different thread without synchronization. What level of synchronization is needed depends on what you are actually reading. For primitive types, you should have a look at atomic reads, e.g. in the form of std::atomic<bool>. The reason synchronization is always needed is that the processors … Read more

Spring @RequestParam mapping Boolean based on 1 or 0 instead of true or false

I think we may need more detail in order to be effective answering your question. I have working Spring 3.2 code along the lines of: @RequestMapping(value = “/foo/{id}”, method = RequestMethod.GET) @ResponseBody public Foo getFoo( @PathVariable(“id”) String id, @RequestParam(value=”bar”, required = false, defaultValue = “true”) boolean bar) { … } Spring correctly interprets ?bar=true, ?bar=1, … Read more

How to check if String value is Boolean type in Java?

parseBoolean(String) returns true if the String is (case-insensitive) “true”, otherwise false valueOf(String) ditto, returns the canonical Boolean Objects getBoolean(String) is a red herring; it fetches the System property of the given name and compares that to “true” There exists no method to test whether a String encodes a Boolean; for all practical effects, any non-“true”-String … Read more

WPF Radiobutton (two) (binding to boolean value)

<RadioButton GroupName=”Group1″ IsChecked=”{Binding PropertyValue}” Content=”Yes” /> <RadioButton GroupName=”Group1″ Content=”No” IsChecked=”{Binding PropertyValue, Converter={StaticResource BoolInverterConverter}}” /> public class BoolInverterConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is bool) { return !(bool)value; } return value; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) … Read more