overloading

How do I call overloaded Java methods in Clojure

て烟熏妆下的殇ゞ 提交于 2019-11-30 16:40:00
问题 For this example Java class: package foo; public class TestInterop { public String test(int i) { return "Test(int)"; } public String test(Object i) { return "Test(Object)"; } } When I start Clojure and try to call the test(int) method, the test(Object) method is called instead, because Clojure automatically boxes the integer into a java.lang.Integer object. How do I force Clojure to call the test(int) method? user=> (.test (new foo.TestInterop) 10) "Test(Object)" I want to call methods like

How to write Java function that returns values of multiple data types?

為{幸葍}努か 提交于 2019-11-30 16:34:15
问题 For example, I want to create a function that can return any number (negative, zero, or positive). However, based on certain exceptions, I'd like the function to return Boolean FALSE Is there a way to write a function that can return an int or a Boolean ? Ok, so this has received a lot of responses. I understand I'm simply approaching the problem incorrectly and I should throw some sort of Exception in the method. To get a better answer, I'm going to provide some example code. Please don't

Why doesn’t Swift call my overloaded method with a more specific type?

我怕爱的太早我们不能终老 提交于 2019-11-30 15:35:05
I use Decodable to decode a simple struct from JSON. This works by conforming to a Decodable protocol: extension BackendServerID: Decodable { static func decode(_ json: Any) throws -> BackendServerID { return try BackendServerID( id: json => "id", name: json => "name" ) } } I’d like to be able to call decode with a String , though, so I have added an extension: extension Decodable { static func decode(_ string: String) throws -> Self { let jsonData = string.data(using: .utf8)! let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: []) return try decode(jsonObject) } } Then

Overloading (or alternatives) in Python API design

↘锁芯ラ 提交于 2019-11-30 15:01:24
I have a large existing program library that currently has a .NET binding, and I'm thinking about writing a Python binding. The existing API makes extensive use of signature-based overloading. So, I have a large collection of static functions like: Circle(p1, p2, p3) -- Creates a circle through three points Circle(p, r) -- Creates a circle with given center point and radius Circle(c1, c2, c3) -- Creates a circle tangent to three curves There are a few cases where the same inputs must be used in different ways, so signature-based overloading doesn't work, and I have to use different function

C# Optional Parameters or Method Overload? [duplicate]

半城伤御伤魂 提交于 2019-11-30 14:33:26
问题 This question already has answers here : method overloading vs optional parameter in C# 4.0 [duplicate] (11 answers) Closed 6 years ago . Since C# added optional parameters is it considered a better practice to use optional parameters or method overloads or is there a particular case where you would want to use one over the other. i.e a function w/ lots of parameters would be better suited w/ optional parameters? 回答1: Optional parameters are nice, but should be used when it makes sense.

Avoid MATLAB startup warning when overloading buildin functions?

此生再无相见时 提交于 2019-11-30 14:07:38
As described here , I created my own figure.m which nicely overloads the built-in figure command. Now, whenever I start MATLAB I get the warning Warning: Function C:\somepath\figure.m has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. Is there any way to deactivate this warning, given that it is desired behavior in my case? You might say that I should call my function differently instead of overloading, but I do feel for my development system this overloading is the right way to go... Update As mentioned by Aabaz you can globally turn

Overloading comparision operator in C++ results in “invalid operator<”

亡梦爱人 提交于 2019-11-30 14:07:11
Currently attempting to sort a vector of object, with each object containing a string, in C++ The strings can contain letters or numbers (due to a design constraint, this is necessary, as the comparator can be changed). At the moment, the class of the object is overloaded, so that when two objects are compared, the strings they contain are compared. This works to a point -- however, when I use a sort operation (such as STL sort) to put the objects in order, it will sort three strings such as "1", "4", "12", in the order "1", "12", "4". 4 is greater then 12, but because it begins comparing from

Python overload primitives

為{幸葍}努か 提交于 2019-11-30 13:45:39
I'm trying to overload some methods of the string builtin. I know there is no really legitimate use-case for this, but the behavior still bugs me so I would like to get an explanation of what is happening here: Using Python2, and the forbiddenfruit module. >>> from forbiddenfruit import curse >>> curse(str, '__repr__', lambda self:'bar') >>> 'foo' 'foo' >>> 'foo'.__repr__() 'bar' As you can see, the __repr__ function as been successfully overloaded, but isn't actually called when when we ask for a representation. Why is that? Then, how would you do to get the expected behaviour: >>> 'foo' 'bar

Generic method to perform a map-reduce operation. (Java-8)

拈花ヽ惹草 提交于 2019-11-30 13:24:30
How to overload a Function with generic parameter in Java 8? public class Test<T> { List<T> list = new ArrayList<>(); public int sum(Function<T, Integer> function) { return list.stream().map(function).reduce(Integer::sum).get(); } public double sum(Function<T, Double> function) { return list.stream().map(function).reduce(Double::sum).get(); } } Error: java: name clash: sum(java.util.function.Function<T,java.lang.Double>) and sum(java.util.function.Function<T,java.lang.Integer>) have the same erasure CKing The example you present in your question has got nothing to do with Java 8 and everything

Inheriting from instance in Python

﹥>﹥吖頭↗ 提交于 2019-11-30 12:34:35
In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example: A = Parent(x, y, z) B = Child(A) This is a hack that I thought might work: class Parent(object): def __init__(self, x, y, z): print "INITILIZING PARENT" self.x = x self.y = y self.z = z class Child(Parent): def __new__(cls, *args, **kwds): print "NEW'ING CHILD" if len(args) == 1 and str(type(args[0])) == "<class '__main__.Parent'>": new_args = [] new_args.extend([args[0].x, args[0].y, args[0].z]) print "HIJACKING" return Child(*new_args) print "RETURNING FROM NEW IN