Questions tagged [methods]

12963 questions
0

votes
2

answer
34

Views

How to update a global variable inside `where` clause in LINQ?

I want to filter a list using LINQ with Where extension method. But apart from filtering I also want to update a global variable inside Where. However I cannot do it. Consider this example: var list = new List { '1', '2', '3', '4', '5' }; bool flag = false; var newList = list.Where(item => { flag =...
-2

votes
2

answer
30

Views

Question: Howto change a funtion to a class in python

I want to create a class with methods, so that I do not have to create multiple functions. Below is my code, I want to get a class with two methods. Method 1: SQL Query, method 2: sql insert. Any tipp is greatly appreciated. Stefan def dbconnect(): dbconn = pymysql.connect(host='192.168.1.2', port=3...
Stefan
1

votes
4

answer
31

Views

Replacing an object in an array with places

The function adds an object to the array and makes it second in the list. But in this case, I clung to the object and I know what his number after creation (5). How to make it so that it is always added second? const arr = [{ 'name': 'BMW', 'price': '55 000', 'country': 'Germany', 'certificate':...
Gregori Roberts
1

votes
3

answer
41

Views

Sorting an object in an array through a method

This function sorts an array. First, the objects in which the country is equal to the one specified in the second argument should be displayed. Then all the rest. But I can not understand what is wrong? const arr = [ { 'name':'BMW', 'price':'55 000', 'country':'Germany', 'certificate':'yes'...
Gregori Roberts
0

votes
0

answer
26

Views

how to get local variables of a method from another class

I have two classes A and B A class contains a method which has some of the local variables. now I want to fetch their name and data type in the B class. can you please help me with this. I researched about java reflection. but I found that I can not achieve this by using reflection, as local variab...
Shweta
0

votes
1

answer
28

Views

How to add a function as a method to a returned array?

I have a function intended to be used with the new constructor. It should return an array with a value of ['Hello World'] and include functions as methods. Here is a sample/demo (sorry if it's a little ugly): var my_object = function () { this.foo = function (data) { // alert and add new item alert(...
CW3
0

votes
0

answer
9

Views

TypeError: 'int' object is not subscriptable: adding a column with a calculation

I have found the code of a bisection method in Python. This is a method to find the root of a function. This function depends on several variables. The function and the bisection method works perfect. However, I now created a dataframe with multiple rows (>1000) where I want to apply the function to...
1

votes
2

answer
4.3k

Views

PHP: Call an internal (Function) method within the same class

Rather than having multiple lines of the same code on each method, I want to set up a (Boot/initialization) method to define common values and such. Then, call that method when needed. Initially, I had something like this: But I would get an error saying something like: Parse error: syntax error, un...
Omar
0

votes
1

answer
22

Views

Pointer in C only updates once when method is called

I am doing a program to mimic the hare and turtle race. I dont understand why my pointer for the turtle movement only updates once when the condition is met multiple times. #include #include #include #define SIZE 70 void turtleMove(char raceTrack[SIZE], char *tPtr); int main() { char raceTrack[S...
RyM
0

votes
0

answer
6

Views

Why do pointers implement interface with pointer receivers, but not vice versa?

Not a duplicate of X does not implement Y (... method has a pointer receiver) There are many questions regarding errors that arise from mixing regular and pointer receivers when implementing an interface on a type. I understand the fixes and proper design concepts for this, but don't understand why...
robbieperry22
1

votes
1

answer
31

Views

How is == method in scala is different from == operator in java? [duplicate]

This question already has an answer here: What's the difference between == and .equals in Scala? 5 answers What is the difference between == and equals() in Java? 22 answers == operator in Java compares two object references and whether or not they are are pointing to same object references,it res...
Gaurav Gupta
0

votes
0

answer
14

Views

GTE operator throws an error, but .__gte__() is fine in python3

I have two custom Python3 objects: MinMax() (from my own code) and DateTime() (from the pendulum package). A MinMax() object represent a range of either numbers or datetimes, defined by a minimum value and maximum value. These values start as None, and once assigned, cannot be reassigned. MinMax() h...
snazzybouche
0

votes
0

answer
22

Views

Is there a way to print two Java methods in two columns?

I'm making a Battleship game with two players and I have several classes. In my main class, I call the same method twice to print my board and the other players' boards. Is there a way to print both on the same lines but separated by some padding? //Prints the board to the console public void printB...
Nikhil Katti
4

votes
4

answer
148

Views

Fast way to find all vectors similar to a given one

By 'similar vector' I define a vector that differs from a given one at just one position by either -1 or 1. However, if the element of the given one is zero, only difference by 1 is possible. Examples: similar_vectors(np.array([0,0,0])) array([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]]) simi...
WojciechR
4

votes
3

answer
120

Views

Java bad practice doing: new… ().doSomething()?

I just saw a piece of code that had some classes with only one method. I picked an examples: public class TempDirCleanupProcess { public void cleanup(final File directory) {} } Then, later on in the code the method was called the following way: new TempDirCleanupProcess().cleanup(tempDir); Now I am...
ItFreak
1

votes
1

answer
43

Views

How to define an extention method for a non-generic array?

I cannot figure out what is the correct syntax to define an extension method on a non-generic array. This question deals with generic arrays, but trying a similar construct for a byte array doesn't work. I have tried a lot of options: type Byte ``[]`` with type byte ``[]`` with type Byte array with...
Kapol
1

votes
2

answer
28

Views

Replace(), replacing a value not specified

I've been learning Javascript via FCC for 6 weeks now, and decided to spend a week learning, and playing around with methods to get really close and comfortable with using them in loops, and with statements. Just playing around with strings, I was trying to replace the string 'I like milk', with 'I...
Adag89
1

votes
1

answer
129

Views

C++ method in thread. Difference between passing: object, object's address, std::ref of object

I am trying to execute an object's method in a C++ thread. I am able to do it, by passing the method's address and the object (or the object's address, or std::ref(my_obj)) to the thread's constructor. I observed that if I pass the object, rather than the object's address or std::ref(my_obj), then...
Michele Piccolini
1

votes
2

answer
71

Views

invoke the extension method of a class without using static class but by using class iteslf using reflection

I want invoke Method2 which is an extension method of a MyClass using MyClass type. I am wondering if this is possible or not. using System; using System.Linq; using System.Reflection; namespace ConsoleApplication9 { public static class MyClassStatic { public static void Method2(this ConsoleApp2.MyC...
D J
1

votes
2

answer
86

Views

Smalltalk (Pharo) methods

I am trying to learn Smalltalk (Pharo), but since not so many documentaion available I would like to ask for some help. I have There two classes, CarRental and Car, and a Test class, CarRentalTest. Now, supporse rental service has a fixednuber of cars. | carRental | carRental := CarRental new. ca...
dnobl
1

votes
1

answer
47

Views

Calling methods in two different classes: Calling eachothers' methods [duplicate]

This question already has an answer here: Why am I receiving a stack overflow? 2 answers I have 2 different classes that are both calling methods from each other. For some reason, when I added an object in the class that had already had an object called from the other class, it gives me a stack ove...
Confused
1

votes
1

answer
46

Views

Lambda return method which calls method that throws exception

I have following issue. I'm working within a method 1 and this method 1 should return an object of a certain class. For my return statement I call another method 2 (which of course returns an object of said class). Though this other method 2 throws an exception. How should I write my return statemen...
SimonartM
1

votes
2

answer
27

Views

Is it possible to set a default method for a class in python? [duplicate]

This question already has an answer here: How to create a custom string representation for a class object? 4 answers Suppose you have a class in python. We'll call it C. And suppose you create an instance of it somewhere in your script, or in interactive mode: c=C() Is is possible to have a 'defaul...
Mannix
1

votes
2

answer
97

Views

How can I macro #define a static method call in C++?

I am trying to write software that can behave differently based on whether or not a certain component should be simulated in software or execute on real hardware. However, GCC complains that the Scope resolution operator (::) cannot be used in a macro, so my question is: is it possible to define a m...
xyzhou
1

votes
3

answer
64

Views

How do I create a get method to return both a String and an integer?

I'm trying to create a getCalories method in which I have to return a String together with an integer but I'm getting an error saying that one cannot be converted to another. How do I make this work? package task14; import java.util.ArrayList; public class Meal { ArrayList ingredient = new ArrayList...
1

votes
3

answer
39

Views

Adding a new object to the array [duplicate]

This question already has an answer here: How to concat arrays immutable way JS 3 answers This function changes my array by adding a new object to it (a new object is passed in the second argument). What method can I use to return a new array, and not change the old array? const arr = [ { 'name':...
Gregori Roberts
0

votes
0

answer
28

Views

Can't find main(String[]) method in class: TapeDeck. The main method is in the other class which runs the program

I have two classes. When the I put class TapeDeckTestDrive first on the text editor, it runs fine. When I put the TestDrive class first, it gives the error that it can't find the main class. Why is this? class TapeDeck { boolean canRecord = false; void playTape(){ System.out.println('tape playing');...
Abdul Hussain
0

votes
1

answer
21

Views

How to extend basic manager in django?

How to add custom method to the basic django manager? ModelNmame.objects.custom_method()
roziukp
0

votes
2

answer
18

Views

How to get return of index of minimum and maximum value in array?

I am doing my homework where I should get maximum and minimum index in an array. I already did that, but I can't understand how to make a return of this index. package MaxMinArrayIndex.bozhko; public class MaxMinArrayIndex { public static void main(String[] args) { gettingIndex(); } private static i...
Ivan Bozhko
1

votes
4

answer
1.6k

Views

C++ Compile-time polymorphism

There two unrelated structures A and B template struct A {}; template struct B {}; one enum type typedef enum { ma, mb} M; and class C containing function templates class C { public: template static void f1 ( A &a) {} template static void f2 ( B &b) {} template static void algo (U &u, M m)...
justik
0

votes
0

answer
3

Views

Method referring to a pulled in packaged's method moves out of scope when put inside an objects method

When I put a method that refers to a pulled in package inside another method it leaves scope and fails. What is the proper way to do this. I tried playing with the 'self' but am new and that did not work out. Desired solution. Does not work. Returns error. undefined method `accounts' for nil:NilCla...
seamus
0

votes
1

answer
23

Views

Use a method multiple times with different parameters efficiently

So i've got an API written in PHP to update/add/remove entries in my database, i use C# to communicate with PHP (post data). But i don't want to have multiple methods with basically almost the same code that does something different. This is how my methods look like to update a member in my databas...
Siy
1

votes
0

answer
43

Views

I have trouble with Message Filter Extension about extracting time or state of message handled

I'm building an app that has Message Filter Extension. And I need to know what message was filtered. But I don't have permission to write in share groups. What I need to know just time and state of message. I have tried so many ways but they did't work .
Huy Bùi
1

votes
2

answer
242

Views

Calling fragment method from Asynctask PostExecute

I need help on how to call a method that is in a fragment from a class AsyncTask. I've been looking to similar questions, I've tried some things and it has not worked for me. The problem: The AsyncTask class downloads an XML and saves some tags that interest me. Next in the method onPostExecute I ha...
Splanas00
1

votes
0

answer
57

Views

Why is it possible to call static class methods by replicating the class name prefix multiple times? [duplicate]

This question already has an answer here: Calling a static method by repeating the object name? 3 answers Why is there an injected class name? 1 answer class E { public: static void f() {}; }; int main() { E::f(); E::E::f(); E::E::E::E::f(); } why is it possible to do this ? It does not work with...
Silviu
1

votes
0

answer
114

Views

Intel IPP functions for arrays beyond 32-bit size limits?

I’m evaluating Intel IPP to speed up certain parts of our code, e.g., adding absolute value sorting among others. I note this page in the manual: While the rest of Intel IPP functions support only signals or images of 32-bit integer size, Intel IPP platform-aware functions work with 64-bit object...
Ahmed Fasih
1

votes
1

answer
418

Views

Better way to write method either POJO or Utility?

Which is the better way to create method 1)Create static method in DataUtils.java class or 2)Create method in pojo Claimheader.java class . My question is if we create a method in POJO class it will affect any performance . In our project, we have lots of methods added in POJO class with only get...
Sitansu
1

votes
0

answer
117

Views

Should I go tightly coupled, with singleton, or loosely coupled, without a singleton? Azure Services, Xamarin Forms

I am making a Xamarin Forms Cross platform app. I have been trying to figure out how to go about getting my app to integrate with the Azure Backend the best way. I have ran into a problem. It has been drilled into my head to try to build programs as loosely coupled as possible. But then I have been...
John Butler
1

votes
0

answer
35

Views

Event duration prediction in R? need tips for methods and packages

I have a general question of methodology. I have to create a model to predict when/after how many days of therapy a patient reaches a certain value. I have data of this value from tight laboratory controls and also information on some influence variables. But now I'm at a loss and I don't know...
SomeKindOfDesaster

View additional questions