class

What happens to casts using generics - (T)object - at run-time in Java?

与世无争的帅哥 提交于 2020-01-03 16:52:33
问题 As far as I understand, Java Generics erases all the information concerning the parameter type T in the generic method (or in the generic class). That's why we can't use new expression, such as new T() instanceof expression, such as if(obj instanceof T) inside a generic method. My question is how the parameter type T works inside a generic method when it comes to casting. For example, I have 3 simple classes here: public class People { String name; public String getName() { return name; }

Template (C++) - not sure if correct

自作多情 提交于 2020-01-03 16:48:23
问题 I'm a student and I'm doing a static library for arrays in C++, so I don't have to rewrite code every time during lessons. I'm at second year in a secondary school so I'm not an expert. I want my code to be compatible with all type (int, float, ecc.) but I'm having some trouble. Can you give a look at my code? // slarray.h #if !defined _SLARRAY_ #define _SLARRAY_ template <typename Tipo> class Array { public: void inserisci(); void visualizza(); void copia(Tipo*); Array(short); ~Array();

Template (C++) - not sure if correct

吃可爱长大的小学妹 提交于 2020-01-03 16:48:06
问题 I'm a student and I'm doing a static library for arrays in C++, so I don't have to rewrite code every time during lessons. I'm at second year in a secondary school so I'm not an expert. I want my code to be compatible with all type (int, float, ecc.) but I'm having some trouble. Can you give a look at my code? // slarray.h #if !defined _SLARRAY_ #define _SLARRAY_ template <typename Tipo> class Array { public: void inserisci(); void visualizza(); void copia(Tipo*); Array(short); ~Array();

What is the proper way of seeding std::mt19937 with std::chrono::high_resolution_clock inside a class?

戏子无情 提交于 2020-01-03 15:39:49
问题 First off, hello everyone! This is my first ever question here, so I hope I am not screwing up. I googled a lot before writing here. I am new to coding, to c++ and I am learning it on my own. Considering that I was told that it is a good practice (i'm probably wrong here) to only seed any Random Engine once, what is the proper / best / more efficient way of using std::mt19937 from the random standard library inside a class, seeded by std::chrono::high_resolution_clock::now().time_since_epoch(

What is the proper way of seeding std::mt19937 with std::chrono::high_resolution_clock inside a class?

◇◆丶佛笑我妖孽 提交于 2020-01-03 15:38:09
问题 First off, hello everyone! This is my first ever question here, so I hope I am not screwing up. I googled a lot before writing here. I am new to coding, to c++ and I am learning it on my own. Considering that I was told that it is a good practice (i'm probably wrong here) to only seed any Random Engine once, what is the proper / best / more efficient way of using std::mt19937 from the random standard library inside a class, seeded by std::chrono::high_resolution_clock::now().time_since_epoch(

Why can't I assign a scalar value to a class using shorthand, but instead declare it first, then set its value?

馋奶兔 提交于 2020-01-03 14:07:22
问题 I am writing a UTF-8 library for C++ as an exercise as this is my first real-world C++ code. So far, I've implemented concatenation, character indexing, parsing and encoding UTF-8 in a class called "ustring". It looks like it's working, but two seemingly equivalent ways of declaring a new ustring behave differently. The first way: ustring a; a = "test"; works, and the overloaded "=" operator parses the string into the class (which stores the Unicode strings as an dynamically allocated int

Why can't I assign a scalar value to a class using shorthand, but instead declare it first, then set its value?

假如想象 提交于 2020-01-03 14:06:11
问题 I am writing a UTF-8 library for C++ as an exercise as this is my first real-world C++ code. So far, I've implemented concatenation, character indexing, parsing and encoding UTF-8 in a class called "ustring". It looks like it's working, but two seemingly equivalent ways of declaring a new ustring behave differently. The first way: ustring a; a = "test"; works, and the overloaded "=" operator parses the string into the class (which stores the Unicode strings as an dynamically allocated int

lumen: App\Http\Controllers\Controller class not found with fresh install

江枫思渺然 提交于 2020-01-03 12:33:12
问题 I'm working with a fresh install of Lumen (building a web API), most things work but when i'm trying to use the router to point to a class i get this error: Fatal error: Class 'App\Http\Controllers\Controller' not found in /Applications/MAMP/htdocs/moments/lumen/app/Http/Controllers/MomentController.php on line 5 This is my router in app/Http/routes.php $app->get('/', 'MomentController@index'); And this is my class in app/Http/Controllers/MomentController.php <?php namespace App\Http

why 2 objects of Integer class in Java cannot be equal

十年热恋 提交于 2020-01-03 11:00:09
问题 my code is: public class Box { public static void main(String[] args) { Integer z = new Integer(43); z++; Integer h = new Integer(44); System.out.println("z == h -> " + (h == z )); } } Output:- z == h -> false why the output is false when the values of both the objects is equal? Is there any other way in which we can make the objects equal? 回答1: You are trying to compare two different object and not their values. z and h points to two different Integer object which hold same value. z == h

How to check instanceof on an argument that is a Class object?

左心房为你撑大大i 提交于 2020-01-03 10:15:07
问题 I'm trying to build a generic class loader. I need to check classes that I load against a method argument to determine if they are of the same class. The code mostly explains what I'm trying to do. private static LinkedList<Object> loadObjectsInDirectory(Class class0, File dir) throws ClassNotFoundException { LinkedList<Feature> objects = new LinkedList<Object>(); ClassLoader cl = new GenericClassLoader(); for(String s : dir.list()) { Class class1 = cl.loadClass(s); try { Object x = class1