class

In java can i have more than one class/object in a file?

馋奶兔 提交于 2020-01-03 02:24:06
问题 So the way i've been told to do things is you have your file and the file name is Classname.java and then the code is something like this: class ClassName { SOME METHODS main {} } and then thats all. I'd like to have two objects defined and used within the same .java file. (i don't want to have to put the other class in a difernt file just because i'd like to send this to someone and i want to avoid hasstle of atatching multiple files to an email [the lazy do make good programers though if

How to specify generic type when the type is only known at runtime?

大憨熊 提交于 2020-01-03 01:21:13
问题 I have some code that I need to generate a generic object on the fly with the generic type of 1 of a set of subclasses: e.g. keyEvent , mouseEvent or appEvent , these all extend event . So, my generic class EventFunction requires a template, however I dont know what the class type is until I recieve the event, so is there a way to do the following: Event event = new KeyEvent(); // FOR EXAMPLE RECIEVING A KEY EVENT // Require an EventFunction with that event class as the generic type

JQuery Hide Div when Option is Selected

▼魔方 西西 提交于 2020-01-02 23:16:34
问题 I want to hide a class of a DIV when a specific OPTION Value is selected <select id="tagtype" name="type"> <option value="type_s">Standard</option> <option value="type_o">Overstock</option> <option value="type_snd">Scratch & Dent</option> <option value="type_mult">Multiples</option> </select> <div class="multiples>stuff here</div> <script type="text/javascript"> $(document).ready(function() { if ($("#tagtype option[value='type_mult']").length) $("multiples").css('display','none'); }); <

Strange behaviour when inheriting from a list in python

坚强是说给别人听的谎言 提交于 2020-01-02 23:15:24
问题 I was fiddling around with inheritance recently and I'm a little confused by the behaviour of the following: class Foo(list): def method(self, thing): new = self + [thing] print(new) self = new print(self) def method2(self, thing): self += [thing] >>> f = Foo([1, 2, 3, 4, 5]) >>> f.method(10) [1, 2, 3, 4, 5, 10] [1, 2, 3, 4, 5, 10] >>> f [1, 2, 3, 4, 5] >>> f.method2(10) >>> f [1, 2, 3, 4, 5, 10] Why does the in-place method method2 work but the first one doesn't? 回答1: Because that's how in

create objects/instances in variables swift

不问归期 提交于 2020-01-02 23:14:35
问题 I don't know how to use variables when creating Instances or adressing them in Swift: For exmaple how do I do following in a loop (creating Instances): class Guest { let name: String var age: Int init(name: String, age: Int) { self.name = name self.age = age } } let guests = [["ann", 1] , ["bob", 2] ...] so that the loop equals : let ann = Guest(name: "ann" , age: 1) let bob = Guest(name: "bob" , age: 2) ... edit: I am looking for something like this: for i in guests { let i[0] = Guest(name:

Class module structure, get same property on different levels

冷暖自知 提交于 2020-01-02 22:16:36
问题 I'm trying to build a class module with my whole Company as follows: Now I know how to achieve this thanks to this answer. The thing is I am on a planning area which will schedule everyone's work and shifts, so I need to add both Dates and timetable... I want to build a timetable for the whole day dividied by every single minute, so 1440 minutes. If I were to write the 2 classes with the properties I need such as Auxiliar Time and Workers on the shift, could I call them from any other class

Delphi GetClass

一个人想着一个人 提交于 2020-01-02 20:13:30
问题 My question is how to access a class which is in an other unit? For an example: program Project1; {$APPTYPE CONSOLE} uses SysUtils, Classes, System, StrUtils, Math, TypInfo, Data in 'Data.pas'; var Str, name, value : string; List, tmpList : TStringList; i : Integer; Obj : TObject; CRef : TPersistentClass; d : TData; begin d := TData(GetClass('Data.TData').Create); Writeln(Format('%s', [d.Name])); Readln; Readln; end. And the Data unit : unit Data; interface uses SysUtils, Classes; type TData

Namespaces within a Python Class

纵饮孤独 提交于 2020-01-02 18:38:41
问题 I have this: class MyClass: """A simple example class""" i = 12345 def f(self): print i # self.i will work just fine return 'hello world' When I do: >>> x = MyClass() >>> >>> x.f() I get an error, as expected. My question is: Why do I get the error? Why is there no namespace between the namespace of the function(or method) definition and the global namespace of the module containing the class? Is there any other way to reference i inside f in this case other than using self? 回答1: You've got

C++ object referencing in classes

耗尽温柔 提交于 2020-01-02 17:13:09
问题 I am wondering how to store a reference of an object inside of another object, and also set that reference as a private property. Example (pseudo-code): class foo { public: int size; foo( int ); }; foo::foo( int s ) : size( s ) {} class bar { public: bar( foo& ); private: foo fooreference; }; bar::bar( foo & reference ) { fooreference = reference; } foo firstclass( 1 ); bar secondclass( firstclass ); As you may be able to see, I just want to be able to store the reference of foo inside this

Count How Many Times a Function is Excuted after the Exceution of Another Function for an Instance of a Class

女生的网名这么多〃 提交于 2020-01-02 16:53:30
问题 Based on this question, I know how to count how many times a function FUNCTION was executed within an instance of a class CLASS . Now, I have another question: How would I count how many times (for one instance of the class CLASS ) a second function FUNCTION2 is executed after the first function FUNCTION is executed ? Here is a small example of how I tried it: class CLASS: # Initializing counting for first function counting_function_execution = 0 def __init__(self,name): self.name = name def