Overload resolution between value, rvalue reference, const lvalue reference

What are the rules here? As there is only one parameter, the rule is that one of the three viable parameter initializations of that parameter must be a better match than both the other two. When two initializations are compared, either one is better than the other, or neither is better (they are indistinguishable). Without … Read more

What is the original type of interpolated string?

The new interpolated string syntax is part compiler magic and part runtime classes. Let’s go through all the scenarios and see what is actually happening. var s = $”{DateTime.Now}”; This gets compiled as this: string s = string.Format(“{0}”, DateTime.Now); See Try Roslyn for details. string s = $”{DateTime.Now}”; This gets compiled as this: string s … Read more

What’s a use case for overloading member functions on reference qualifiers?

In a class that provides reference-getters, ref-qualifier overloading can activate move semantics when extracting from an rvalue. E.g.: class some_class { huge_heavy_class hhc; public: huge_heavy_class& get() & { return hhc; } huge_heavy_class const& get() const& { return hhc; } huge_heavy_class&& get() && { return std::move(hhc); } }; some_class factory(); auto hhc = factory().get(); This does … Read more

Does EL support overloaded methods?

EL does not support it, no. It’ll always be the first method of the Class#getMethods() array whose name (and amount of arguments) matches the EL method call. Whether it returns the same method everytime or not depends on the JVM make/version used. Perhaps you made a Java SE upgrade in the meanwhile as well. The … Read more

Why does java promote long parameter to float/double when there’s no method which accepts long?

Java Language Specification is pretty clear on that (emphasis mine): 15.12.2 Compile-Time Step 2: Determine Method Signature […] The first phase (§15.12.2.2) performs overload resolution without permitting boxing or unboxing conversion […] If no applicable method is found during this phase then processing continues to the second phase. […] The second phase (§15.12.2.3) performs overload … Read more

The call is ambiguous between the following methods or properties

Both constructors take the same number of arguments, but in a different order. Since you have specified default values for the two constructor parameters the compiler cannot distinguish between the two overloads when the second argument is not supplied. I would advise you to remove the existing constructors and replace with the following: public SomeClass(string … Read more

Are Polymorphism , Overloading and Overriding similar concepts? [closed]

Polymorphism can be achieved through overriding. Put in short words, polymorphism refers to the ability of an object to provide different behaviors (use different implementations) depending on its own nature. Specifically, depending on its position in the class hierarchy. Method Overriding is when a method defined in a superclass or interface is re-defined by one … Read more

Java 8 Consumer/Function Lambda Ambiguity

This line is definitely ambiguous: doStuff(getPattern(x -> String.valueOf(x))); Reread this from the linked JLS chapter: A lambda expression (§15.27) is potentially compatible with a functional interface type (§9.8) if all of the following are true: The arity of the target type’s function type is the same as the arity of the lambda expression. If the … Read more