static

我的Java工具类(不断更新)

风流意气都作罢 提交于 2020-01-11 22:43:03
Scanner(要求用户按要求输入int double 数据) //对输入整数进行优化 public class ScannerUtils { //私有构造方法 private ScannerUtils ( ) { } public static int getInt ( ) { while ( true ) { Scanner sc = new Scanner ( System . in ) ; try { //不搞录入语句了 一般都需要按照题目要求写 return sc . nextInt ( ) ; } catch ( Exception e ) { System . out . println ( "别乱搞" ) ; System . out . println ( "再搞让你蓝屏" ) ; } } } public static double getDouble ( ) { while ( true ) { Scanner sc = new Scanner ( System . in ) ; try { System . out . println ( "输入个数!!!!" ) ; return sc . nextDouble ( ) ; } catch ( Exception e ) { System . out . println ( "别乱搞" ) ; System

Can i declare a static variable inside static member function in Java?

寵の児 提交于 2020-01-11 19:45:35
问题 private static int Fibonoci(int n) { static int first=0; static int second=1; static int sum; if(n>0) i am getting a error "Illegal Modifier" and if i remove static keyword there is no error and i need those variables to be static 回答1: You can not declare varibale as static inside a method. Inside method all variables are local variables that has no existance outside this method thats why they cann't be static. static int first=0; static int second=1; static int sum; private static int

C++ static local function vs global function

大城市里の小女人 提交于 2020-01-11 17:18:29
问题 What is the utility of having static functions in a file ? How are they different from having global functions in a file ? static int Square(int i) { return i * i; } vs int Square(int i) { return i * i; } 回答1: What is the utility of having static functions in a file? You can use these functions to provide shared implementation logic to other functions within the same file. Various helper functions specific to a file are good candidates to be declared file-static. How are they different from

Can't set the value of a static TextField in javafx [duplicate]

喜你入骨 提交于 2020-01-11 14:10:16
问题 This question already has an answer here : javafx 8 compatibility issues - FXML static fields (1 answer) Closed 2 years ago . I'm working on a program for Insurance purposes and there I've a textfield called Reference Key this reference key is generated randomly every time I View the panel the other Scenes and classes needs this Reference Key , so I've made it static so that all the classes can reach this Instance directly ! My problem is that when I set the text for the textfield I get an

_beginthreadex static member function

本秂侑毒 提交于 2020-01-11 12:05:15
问题 How do I create a thread routine of a static member function class Blah { static void WINAPI Start(); }; // .. // ... // .... hThread = (HANDLE)_beginthreadex(NULL, 0, CBlah::Start, NULL, NULL, NULL); This gives me the following error: ***error C2664: '_beginthreadex' : cannot convert parameter 3 from 'void (void)' to 'unsigned int (__stdcall *)(void *)'*** What am I doing wrong? 回答1: Sometimes, it is useful to read the error you're getting. cannot convert parameter 3 from 'void (void)' to

Understanding static variables declaration/initialization in C

谁说我不能喝 提交于 2020-01-11 09:56:05
问题 I have only one file in my project called test.c; the code below does not compile if I do not define "TRUE". I use vc. I just want to understand the behavior. Please throw some light on this aspect. #ifdef TRUE static int a; static int a = 1; #else static int a = 1; static int a; #endif int main (void) { printf("%d\n", a); return 0; } ----------------------- #ifdef TRUE // both ok int a; int a = 1; #else // both ok int a = 1; int a; #endif int main (void) { printf("%d\n", a); return 0; } 回答1:

C/C++中的const、static、inline、friend、template、virtual、异常机制等特性

徘徊边缘 提交于 2020-01-11 07:16:46
一、const const关键字的作用 (1)作用: 1)欲阻止一个变量被改变,可使用const,在定义该const变量时,需先初始化,以后就没有机会改变他了; 2)对指针而言,可以指定指针本身为const,也可以指定指针所指的数据为const,或二者同时指定为const; 3)在一个函数声明中,const可以修饰形参表明他是一个输入参数,在函数内部不可以改变其值; 4)对于类的成员函数,有时候必须指定其为const类型,表明其是一个常函数,不能修改类的成员变量; 5)对于类的成员函数,有时候必须指定其返回值为const类型,以使得其返回值不为“左值”。 const修饰变量 变量的值不能改变 const修饰指针 如果const位于*的左侧,则const就是用来修饰指针所指向的变量,即指针指向为常量 如果const位于*的右侧,const就是修饰指针本身,即指针本身是常量 指针常量:不能通过指针来修改变量的值。 常量指针:一直指向该变量,不能给该指针赋予其他地址 函数中使用const const修饰函数参数 表示参数不可变 若参数为引用,可以增加效率 const引用传递和函数按值传递的效果是一样的,但按值传递会先建立一个类对象的副本, 然后传递过去,而它直接传递地址,所以这种传递比按值传递更有效 const按值传递时只是外部对象的拷贝,值的改变不会对外部有什么影响

Execution of Java static blocks in subclasses

人盡茶涼 提交于 2020-01-11 05:21:05
问题 I am preparing myself for Java certification test and I have found an interesting question related to the execution of Java static blocks. I have spent a lot of time reading about this topic, but I didn't find the answer I was looking for. I know that static blocks are executed when the class is loaded into JVM or when the main method is invoked, but... package oneClassTasks; class Parent { static int age; } class Child extends Parent { static { age = 5; System.out.println("child's static

Performance differences between static and non-static final primitive fields in Java

跟風遠走 提交于 2020-01-11 05:04:08
问题 I recently ran across a class that had the following field declared: private final int period = 1000; In this particular case, the author had intended for it to also be static and since the value couldn't be altered at any point, there was no real functional reason not to declare it static, but it got me wondering how Java treats final vs. final static primitives. In particular: 1) How are final static primitives stored? Are they simply compiled directly into the expressions in which they're

Performance differences between static and non-static final primitive fields in Java

南笙酒味 提交于 2020-01-11 05:03:32
问题 I recently ran across a class that had the following field declared: private final int period = 1000; In this particular case, the author had intended for it to also be static and since the value couldn't be altered at any point, there was no real functional reason not to declare it static, but it got me wondering how Java treats final vs. final static primitives. In particular: 1) How are final static primitives stored? Are they simply compiled directly into the expressions in which they're