anonymous

Restrict access to functionality for user by IP address

烈酒焚心 提交于 2021-02-05 00:59:15
问题 I have a website that allows a functionality for any user but each user is only allowed to use it a fixed amount of times. Allow me to go into some more detail, our "anonymous/guest" user is allowed to search on the database for entries only 3 times per 24 hours. Is there a way I can use the IP to track the users attempts at this, restricting them after 3 attempts and then get it to expire after 24 hours? The website is built in PHP but whatever language serves this functionality, I am open

Anonymous initialization of class with protected constructor

穿精又带淫゛_ 提交于 2020-05-25 18:50:02
问题 Let's assume we have a class: public class SomeClass { protected SomeClass () { } } In MainClass located in different package I tried to execute two lines: public static void main(String[] args) { SomeClass sac1 = new SomeClass(); SomeClass sac2 = new SomeClass() {}; } Because of protected constructor, in both cases I was expecting program to fail. To my suprise, anonymous initialization worked fine. Could somebody explain me why second method of initialization is ok? 回答1: Your anonymous

Anonymous initialization of class with protected constructor

安稳与你 提交于 2020-05-25 18:48:19
问题 Let's assume we have a class: public class SomeClass { protected SomeClass () { } } In MainClass located in different package I tried to execute two lines: public static void main(String[] args) { SomeClass sac1 = new SomeClass(); SomeClass sac2 = new SomeClass() {}; } Because of protected constructor, in both cases I was expecting program to fail. To my suprise, anonymous initialization worked fine. Could somebody explain me why second method of initialization is ok? 回答1: Your anonymous

Why can't I use <Class>.this in anonymous class?

非 Y 不嫁゛ 提交于 2020-01-14 09:07:56
问题 I recently use this code, and realize that in anonymous class, I can't access the instance by .this, like this: Sprite sprFace = new Sprite() { @Override protected void onManagedUpdate(float pSecondElapsed) { runOnUpdateThread(new Runnable() { @Override protected void run() { Sprite.this.getParent().detach(Sprite.this); // Here }}); } }; I know how to solve it (just declare a "me" variable), but I need to know why I can't use <Class>.this ? 回答1: The <Class>.this syntax gives a special way of

Passing an anonymous variable by reference

可紊 提交于 2020-01-12 08:00:13
问题 Standard C++ types such as int or char have ctors, so you can have expressions like: int a = int(67); // create anonymous variable and assing it to variable a int b(13); // initialize variable b int(77); // create anonymous variable User defined types (structures or classes) are able to do the same: struct STRUCT { STRUCT(int a){} }; STRUCT c = STRUCT(67); STRUCT d(13); STRUCT(77); The question is: why can we pass by a reference anonymous structure or class instances, but can not pass

What is the equivalent C# code for a VB.NET anonymous delegate?

旧时模样 提交于 2020-01-06 02:13:08
问题 What is the equivalent C# code for the following VB.NET: Dim moo = Function(x as String) x.ToString() I thought that this should work: var moo = (string x) => x.ToString(); but that yielded a compiler error: Cannot assign lamda expression to an implicitly-typed local variable After some further investigation, I discovered that the type of the variable moo ( moo.GetType() ) in the VB example is VB$AnonymousDelegate_0'2[System.String,System.String] Is there anything equivalent to this in C#?

Removing anonymous listener

帅比萌擦擦* 提交于 2020-01-03 16:42:36
问题 When trying to adopt the style of implementing a listener using anonymous or nested class in order to hide the notification methods for other uses than listening (i.e. I don't want anybody to be able to call actionPerformed). For example from java action listener: implements vs anonymous class: public MyClass() { myButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { //doSomething } }); } The question is if theres an elegant way to remove the listener

Is it an Anonymous Array if the resulting array is assigned to a variable

一世执手 提交于 2020-01-02 06:14:47
问题 (I am studying for the Java Associate Exam OCJP 7) A question asked to select examples of illegal initializations. One of the answers was:- int [] k= new int[2]{5,10}; The explanation said that when creating an anonymous array it was illegal to specify the size of the array. From what I know this is NOT an anonymous array as it is named "k". Calling a method such as :- operateOnArray(new int[]{5,10}); Would have been an example of an anonymous array since it is not declared. I can see that

Anonymous class construction

…衆ロ難τιáo~ 提交于 2020-01-02 01:47:10
问题 I need an idea to create anonymous class on PHP. I don't know how I can works. See my limitations : On PHP you can't make anonymous class, like anonymous function (like class {} ); On PHP you don't have class scope (except in namespaces, but it have the same problem below); On PHP you can't use variables to specify the class name (like class $name {} ); I don't have access to install the runkit PECL. What I need, and why : Well, I need create a function called ie create_class() that receives