methods

“generic method” “absolute value” java

风格不统一 提交于 2019-12-13 02:57:15
问题 I want to make a stupid example for my students, but a don´t know if I can do what I´m thinking I want to do the abs method with generics. My idea is something similar to this: public class MiMath { public static <T extends Number> T abs(T objeto) { if (objeto.doubleValue()<0) return (T) -objeto.doubleValue(); else return objeto; } } in this linea return (T) -objeto.doubleValue(); eclipse says that (T) is not a Type 回答1: The problem is that what you are doing here with the (T) is not really a

Ruby setter method syntax method=(value) - Comparison to Java

大城市里の小女人 提交于 2019-12-13 02:57:14
问题 Hello dear stackoverflowers :) I came from Java and have one doubt about the syntax of getters (if it's really just a syntax issue). In java you would have a setter like private void setName(value) { variableName = value; } who would take value as an argument and change the instance variable inside it. In ruby, when I explicitly define a setter (due to constraint reasons), I need to use set_name=(value) or if I use the syntax set_name(value) would be the same? In other words, the = in the end

Background worker report string from a method

♀尐吖头ヾ 提交于 2019-12-13 02:52:38
问题 I've created a copy file method that i would like to wrap around a background worker. I would like the copy file method to report a string back to the UI thread (change a label) on the current file name its on. I can't seem to get it to work and i'm getting cross thread ui errors. Here is my code. Do Work //Textbox Array Values // 0 = computername // 1 = username // 2 = password string[] tbvalues = (string[])e.Argument; string computer = tbvalues[0]; string user = tbvalues[1]; string pass =

How in C# to pass a name of the object as a parameter to function?

核能气质少年 提交于 2019-12-13 02:49:22
问题 I have the code that change the state of boolean property on mouseclick, depending on name of the clicked object: private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { FrameworkElement feSource = e.Source as FrameworkElement; switch (feSource.Name) { case "r1s1": if (r1s1.IsSelected == false) r1s1.IsSelected = true; else r1s1.IsSelected = false; break; case "r1s2": if (r1s2.IsSelected == false) r1s2.IsSelected = true; else r1s2.IsSelected = false; break; .............

How to, from static methods ; access a unique value of a static property used in a static method

﹥>﹥吖頭↗ 提交于 2019-12-13 02:48:14
问题 I want to access the value of a static field in other static methods running on the same thread . An example is in the code below : The first class in this script is ClassA . ClassA's job is to compare two Rect value , If there is inequality between tho two compared Rect values then a public boolean is set to true; in classA , IsRectChanged is a bool method which takes a parameter object of type Rect and compares it to StoredRect which is a Rect . The method returns true when storedRect and

Limit a method to be called only through another method?

耗尽温柔 提交于 2019-12-13 02:43:50
问题 Say i have two methods first_method and second_method as follows. def first_method(some_arg): """ This is the method that calls the second_method """ return second_method(some_arg[1], some_arg[2]) def second_method(arg1, arg2): """ This method can only be called from the first_method or it will raise an error. """ if (some condition): #Execute the second_method else: raise SomeError("You are not authorized to call me!") How can i check (what condition(s)) that second method is being called by

Class exists in an external file

拟墨画扇 提交于 2019-12-13 02:42:27
问题 How do I check an external file for a class? I am trying to setup a install feature for my modules, so I am trying to get it to load a list of directories and then check if the module file has a method called install. So only the modules with this method will be shown in the list. Here is my code so far: $output .= '<div id="module-dialog" title="Add Widget"><form id="widget-list" name="widget-list"> <select name="widgets" size="12" id="widgets-list">'; $dirHandler = opendir('modules') or die

What does the method prod() do in this Java program?

a 夏天 提交于 2019-12-13 02:27:36
问题 public class Prod { public static void main(String[] args) { System.out.println(prod(1, 4)); } public static int prod(int m, int n) { if (m == n) { return n; } else { int recurse = prod(m, n-1); int result = n * recurse; return result; } } } This is an exercise in the book I am stumped on. Why would the program not just recurse until the two numbers are equal and then return n ? Also, where it says, int result = n * recurse; How does it multiply int n by recurse which would be (int, int) ?

Java: successful build but the output is “user_package.Point@68e26d2e”

别来无恙 提交于 2019-12-13 02:22:42
问题 I am learning java and trying to execute a simple script. I have a class Point as the following: package user_package; public class Point { float x; float y; float z; public Point(float x, float y, float z){ this.x = x; this.y = y; this.z = z; } public static Point add(Point p1, Point p2){ return new Point(p1.x + p2.x, p1.y + p2.y, p1.z + p2.z); } } Then I have the main file like this: import user_package.Point; import static user_package.Point.add; class Tutorial{ public static void main

Property is faster than method? Need reason for it

蹲街弑〆低调 提交于 2019-12-13 02:22:27
问题 As I google this question so one person give answer that property is faster than method and give one example of size() and length . He said length is faster than size because length is property. Can you please let me know is it correct ? Or If you will give example then it will be great for me. 回答1: size internally calls the length //http://code.jquery.com/jquery-latest.js // The number of elements contained in the matched element set size: function() { return this.length; }, So if you are