methods

Java and the use of the Final keyword

大城市里の小女人 提交于 2020-01-12 09:16:36
问题 I'm new to Java having programmed in Delphi and C# for some time,. My question relates to the usage of the "final" keyword on a variable that holds an instantiated class when the variable declaration and instantiation both happen within the scope of the same method. e.g. private String getDeviceID() { //get the android device id final TelephonyManager tm = (TelephonyManager)GetBaseContext().getSystemService(Context.TELEPHONY_SERVICE); final String deviceID = tm.getDeviceId(); // log debug

Java and the use of the Final keyword

半世苍凉 提交于 2020-01-12 09:16:13
问题 I'm new to Java having programmed in Delphi and C# for some time,. My question relates to the usage of the "final" keyword on a variable that holds an instantiated class when the variable declaration and instantiation both happen within the scope of the same method. e.g. private String getDeviceID() { //get the android device id final TelephonyManager tm = (TelephonyManager)GetBaseContext().getSystemService(Context.TELEPHONY_SERVICE); final String deviceID = tm.getDeviceId(); // log debug

Concrete Types or Interfaces for return types?

眉间皱痕 提交于 2020-01-12 08:22:13
问题 Today I came to a fundamental paradox of the object programming style, concrete types or interfaces. Whats the better election for a method's return type: a concrete type or an interface? In most cases, I tend to use concrete types as the return type for methods. because I believe that an concrete type is more flexible for further use and exposes more functionality. The dark side of this: Coupling. The angelic one: A concrete type contains per-se the interface you would going to return

Verify a method call using Moq

心不动则不痛 提交于 2020-01-11 15:05:25
问题 I am fairly new to unit testing in C# and learning to use Moq. Below is the class that I am trying to test. class MyClass { SomeClass someClass; public MyClass(SomeClass someClass) { this.someClass = someClass; } public void MyMethod(string method) { method = "test" someClass.DoSomething(method); } } class Someclass { public DoSomething(string method) { // do something... } } Below is my TestClass: class MyClassTest { [TestMethod()] public void MyMethodTest() { string action="test"; Mock

Get String from another method

隐身守侯 提交于 2020-01-11 14:36:30
问题 I have 2 methods, the first one where i display selected value, index from my JList(list). What i want to do is to send selectedValue - s - to CreateMap method. I tried this code, but s variable is null. Why? public void actionPerformed(ActionEvent e) { int index = 0; if(e.getActionCommand().equals("Check")){ //if button is pressed index = list.getSelectedIndex(); System.out.println("Index selected" + index); String s = (String) list.getSelectedValue(); System.out.println("Value Selected " +s

binary to hexa decimal without predefined method (JAVA)

别等时光非礼了梦想. 提交于 2020-01-11 14:25:09
问题 I'm looking for a method that converts binary numbers to hexa decimals (JAVA). Problem is that it can't be done with a predefined method and I just don't know how to do it. I've tried a few things but it throws me off that hexa decimals include chars. thanks in advance! 回答1: For your requirement first of all you have to convert binary no into decimal and then into hexadecimal. So please try this program it works as per your requirement : import java.util.Scanner; public class BinaryToHexa {

How can i fix this equals on primitive type(int)

非 Y 不嫁゛ 提交于 2020-01-11 12:18:51
问题 heres my code for a library application package com.accenture.totalbeginner; public class Person { private String name; private int maximumbooks; public Person() { name = "unknown name"; maximumbooks = 3; } public String getName() { return name; } public void setName(String anyname) { name = anyname; } public int getMaximumbooks() { return maximumbooks; } public void setMaximumbooks(int maximumbooks) { this.maximumbooks = maximumbooks; } public String toString() { return this.getName() + " ("

Simple Java Method won't run. Method inside method

↘锁芯ラ 提交于 2020-01-11 11:35:31
问题 Here is my code: public class Project1mrybak3 { public static void main (String[] args) { System.out.println("Begin Java Exection"); System.out.println(""); // put your Java Program here //choose picture String picfile = FileChooser.pickAFile(); Picture pic = new Picture(picfile); //Create turtle 1 Turtle t1 = new Turtle (pic); t1.setPenWidth(10); //Create turtle 2 Turtle t2 = new Turtle (pic); flower(t1,200); //show picture pic.show(); System.out.println(""); System.out.println("End Java

C++ beginner's coding mistake: “Undeclared identifier”?

孤者浪人 提交于 2020-01-11 10:06:29
问题 I'm to use C++ for a very small part of my project. I must be coding something wrong, but my knowledge of C++ is what it is and I can't get around this... See both the AbstractContactListener.h and .mm files below. The problem is in isFixtureCollidingWithFixtureOfType(...) method, I can't access the _contact vector. What could I be doing wrong here? header: struct JRContact { b2Fixture *fixtureA; b2Fixture *fixtureB; bool operator==(const JRContact& other) const { return (fixtureA == other

What does “this” mean in a static method declaration?

China☆狼群 提交于 2020-01-11 08:42:08
问题 I've seen some code that uses the keyword this in the function parameter declaration. For example: public static Object SomeMethod( this Object blah, bool blahblah) What does the word this mean in that context? 回答1: It means SomeMethod() is an extension method to the Object class. After defining it you can call this method on any Object instances (despite it being declared static ), like so: object o = new Object(); bool someBool = true; // Some other code... object p = o.SomeMethod(someBool)