Skip to main content

Questions tagged [wrapper]

A wrapper is an OOP technique where an object encapsulates (wraps) another object, resource (dynamically allocated memory, OS file/widow handle, socket, thread mutex, etc) or a set of subroutines, hiding/protecting it and providing another (possibly easier to use) interface. When using this tag on implementation heavy questions - tag the code language the implementation is written in.

Filter by
Sorted by
Tagged with
248 votes
17 answers
259k views

What is a wrapper class?

What is a wrapper class? How are such classes useful?
Bhaskar's user avatar
  • 4,249
214 votes
12 answers
169k views

How to use C++ in Go

In the new Go language, how do I call C++ code? In other words, how can I wrap my C++ classes and use them in Go?
Frank's user avatar
  • 65.5k
201 votes
7 answers
228k views

Java: Integer equals vs. ==

As of Java 1.5, you can pretty much interchange Integer with int in many situations. However, I found a potential defect in my code that surprised me a bit. The following code: Integer cdiCt = ...; ...
Jeremy Goodell's user avatar
148 votes
7 answers
116k views

Cannot add task 'wrapper' as a task with that name already exists

When installing 'react-native init AwesomeProject' I get this error when I run react-native run-android: Could not determine java version from '11.0.1'. A quick google suggests I need to update the ...
Ben Kemp's user avatar
  • 1,511
120 votes
11 answers
97k views

When to use wrapper class and primitive type

When I should go for wrapper class over primitive types? Or On what circumstance I should choose between wrapper / Primitive types?
Gopi's user avatar
  • 5,829
101 votes
5 answers
60k views

How to decorate all functions of a class without typing it over and over for each method? [duplicate]

Lets say my class has many methods, and I want to apply my decorator on each one of them, later when I add new methods, I want the same decorator to be applied, but I don't want to write @mydecorator ...
rapadura's user avatar
  • 5,292
100 votes
6 answers
60k views

Developing C wrapper API for Object-Oriented C++ code

I'm looking to develop a set of C APIs that will wrap around our existing C++ APIs to access our core logic (written in object-oriented C++). This will essentially be a glue API that allows our C++ ...
theactiveactor's user avatar
92 votes
5 answers
39k views

Vue - how to pass down slots inside wrapper component?

So I've created a simple wrapper component with template like: <wrapper> <b-table v-bind="$attrs" v-on="$listeners"></b-table> </wrapper> using $attrs and $listeners to ...
user3599803's user avatar
  • 6,872
84 votes
11 answers
73k views

Can you alter a Javascript function after declaring it?

Let's say I have var a = function() { return 1; }. Is it possible to alter a so that a() returns 2? Perhaps by editing a property of the a object, since every function is an object? Update: Wow, ...
pr1001's user avatar
  • 21.9k
78 votes
14 answers
47k views

Making decorators with optional arguments [duplicate]

from functools import wraps def foo_register(method_name=None): """Does stuff.""" def decorator(method): if method_name is None: method.gw_method = method.__name__ ...
orokusaki's user avatar
  • 56.5k
77 votes
10 answers
80k views

General decorator to wrap try except in python?

I'd interacting with a lot of deeply nested json I didn't write, and would like to make my python script more 'forgiving' to invalid input. I find myself writing involved try-except blocks, and would ...
Mittenchops's user avatar
  • 19.4k
76 votes
3 answers
37k views

How to test an internal class in a class library?

I would like to write a class library which creates for me a complex object but should only be exposed as little as possible. I want it to be included into other projects and there I only have one ...
Thomas Mondel's user avatar
69 votes
8 answers
27k views

Using == operator in Java to compare wrapper objects

I'm reading SCJP Java 6 by Kathy Sierra and Bert Bates and this book is confusing me so much. On page 245 they state that the following code below. Integer i1 = 1000; Integer i2 = 1000; if(i1 != i2) ...
dido's user avatar
  • 3,377
59 votes
5 answers
5k views

How many objects are created by using the Integer wrapper class?

Integer i = 3; i = i + 1; Integer j = i; j = i + j; How many objects are created as a result of the statements in the sample code above and why? Is there any IDE in which we can see how many ...
Syamesh K's user avatar
  • 826
52 votes
5 answers
122k views

What is the meaning of a C++ Wrapper Class?

I have a little trouble in understanding a wrapper class. It would be great if some one could help providing apt examples. What is a C++ Wrapper Class and what are the circumstances of writing it ? ...
Mahesh's user avatar
  • 34.4k
48 votes
5 answers
46k views

How to convert Integer[] to int[] array in Java?

Is there a fancy way to cast an Integer array to an int array? (I don't want to iterate over each element; I'm looking for an elegant and quick way to write it) The other way around I'm using ...
Michael Brenndoerfer's user avatar
48 votes
3 answers
30k views

What's the relative order with which Windows search for executable files in PATH?

If I have a.com, a.cmd, a.bat, and a.exe files in my %PATH%, which one would Windows pick if I invoke just the command a? Is this officially spec-ed somewhere by Microsoft? I just wanted to wrap my ...
Jeenu's user avatar
  • 2,189
48 votes
10 answers
30k views

How to safely wrap `console.log`?

Suppose I want to include some calls to console.log for some legitimate production reason, say for something like a unit test harness. Obviously I would not want this to throw a premature exception if ...
Dagg Nabbit's user avatar
  • 76.4k
48 votes
2 answers
98k views

Creating simple c++.net wrapper. Step-by-step

I've a c++ project. I admit that I'm a complete ZERO in c++. But still I need to write a c++.net wrapper so I could work with an unmanaged c++ library using it. So what I have: 1) unmanaged project's ...
Evgeny007's user avatar
  • 642
43 votes
3 answers
8k views

Exposing `defaultdict` as a regular `dict`

I am using defaultdict(set) to populate an internal mapping in a very large data structure. After it's populated, the whole structure (including the mapping) is exposed to the client code. At that ...
max's user avatar
  • 51.2k
41 votes
6 answers
83k views

How do I wrap a function in Javascript?

I'm writing a global error handling "module" for one of my applications. One of the features I want to have is to be able to easily wrap a function with a try{} catch{} block, so that all calls to ...
Daniel Magliola's user avatar
41 votes
3 answers
64k views

Parent div is smaller than child div?

here's my question, i want to fill the content div with white. BUT when i do it , its not filling the whole div. The child div are more bigger and they go over the parent div (content). I want that ...
user1440480's user avatar
40 votes
2 answers
11k views

What is the difference between a wrapper, a binding, and a port?

In a software portability context, what is the difference between these three concepts? For example, I want to use the ncurses library, the original ncurses library is written in C, but my ...
user478249's user avatar
39 votes
8 answers
29k views

Simple way to get wrapper class type in Java

I have a piece of code where I need to pass the class of a field in a method. Because of the mechanics of my code I can only handle reference objects and not primitives. I want an easy way of ...
Savvas Dalkitsis's user avatar
37 votes
2 answers
16k views

Java: Is there a difference between L and l (lowercase L) when specifying a long?

When I specify a number to be a long with a constant value 400, is there any difference between using 400L and 400l? Does it have some relationship to the wrapper type? Is L used to get a wrapper ...
Lippstadtfreak's user avatar
32 votes
3 answers
13k views

How to wrap a function using varargin and varargout?

mini-example: function varargout = wrapper(varargin) varargout = someFunction(varargin); That's how I'd do it first. But for example if someFunction = ndgrid this yields a not defined for cell ...
Tobias Kienzler's user avatar
31 votes
3 answers
29k views

How to wrap every method of a class? [duplicate]

I'd like to wrap every method of a particular class in python, and I'd like to do so by editing the code of the class minimally. How should I go about this?
rjkaplan's user avatar
  • 3,368
30 votes
3 answers
39k views

wrapper printf function that filters according to user preferences

My program writes to a log and to stdout. Every message, however, has a certain priority and the user specifies in Preferences which priorities go to which stream (log or stdout). unsigned short ...
wsd's user avatar
  • 1,246
29 votes
6 answers
77k views

What is the radix parameter in Java, and how does it work?

I understand that radix for the function Integer.parseInt() is the base to convert the string into. Shouldn't 11 base 10 converted with a radix/base 16 be a B instead of 17? The following code prints ...
Minh Tran's user avatar
  • 793
28 votes
6 answers
16k views

How to fake type with Python

I recently developed a class named DocumentWrapper around some ORM document object in Python to transparently add some features to it without changing its interface in any way. I just have one issue ...
Pierre's user avatar
  • 6,134
28 votes
2 answers
13k views

Does C++11 have wrappers for dynamically-allocated arrays like Boost's scoped_array?

I often need to deal with dynamically-allocated arrays in C++, and hence rely on Boost for scoped_array, shared_array, and the like. After reading through Stroustrup's C++11 FAQ and the C++11 ...
void-pointer's user avatar
  • 14.6k
27 votes
1 answer
8k views

BOOL wrapper? Make an object of `BOOL` value. (Objective-C)

How do I wrap a BOOL in an object type in Objective-C? I want to store a BOOL in the userInfo object of an NSTimer. How do I wrap it?
Shade's user avatar
  • 9,971
26 votes
3 answers
37k views

Automatically generate C# wrapper class from dll in Visual Studio 2010 Express?

I was told by a colleague of mine that Visual Studio allows one to point to a .dll and auto-magically generate a C# wrapper class. Is this really possible? And if so, how does one go about achieving ...
mre's user avatar
  • 44k
25 votes
11 answers
21k views

Java vs. C++ for building a GUI which has a C++ backend [closed]

I currently have a C++ backend that I need to connect with a GUI, and since I've never built a GUI before, I was confused on where to start. I'm comfortable writing code in C++ and Java, so I'd ...
sparkFinder's user avatar
  • 3,384
25 votes
1 answer
19k views

vue wrap another component, passing props and events

How can I write my component to wrap another vue component, while my wrapper component get some extra props? My wrapper template component should be: <wrapper-component> <v-table><...
user3599803's user avatar
  • 6,872
25 votes
3 answers
8k views

What is the best way to call into Swift from C?

Calling into C from Swift is pretty simple, however I'm looking into making a bi-directional wrapper in C, so my C has to call Swift functions. Right now, I can do this by declaring function pointers ...
Dan's user avatar
  • 1,298
24 votes
2 answers
32k views

How to implement a builder class using Generics, not annotations?

I want to write a generic builder class which wraps around any java class and providing setter functions of a specific style. I am not sure if this could be called "dynamically generated functions". ...
towi's user avatar
  • 22k
23 votes
4 answers
16k views

Are all primitive wrapper classes immutable objects?

Are all primitive wrapper classes in Java immutable objects? String is immutable. What are the other immutable objects?
Jothi's user avatar
  • 15k
23 votes
5 answers
6k views

Java Wrapper equality test

public class WrapperTest { public static void main(String[] args) { Integer i = 100; Integer j = 100; if(i == j) System.out.println("same"); else ...
Warrior's user avatar
  • 39.3k
23 votes
4 answers
27k views

Rule of thumb for naming wrapper classes

I find myself creating a significant number of wrapper classes, purely because I want to mock out the behaviour of Classes that don't lend themselves well to the RhinoMocks isolation model (for ...
jpoh's user avatar
  • 4,576
23 votes
1 answer
2k views

Why is this method overloading ambiguous?

public class Primitive { void m(Number b, Number ... a) {} // widening, autoboxing->widening->varargs void m(byte b, Number ... a) {} // unboxing, autoboxing->widening->varargs ...
Aman's user avatar
  • 989
23 votes
5 answers
8k views

Generate C wrapper from C++?

I want to generate C wrappers from C++ libraries. There are tutorials on how to do it by hand: http://dsc.sun.com/solaris/articles/mixing.html http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp....
numeric's user avatar
  • 475
22 votes
3 answers
6k views

Is there a way to autogenerate wrappers in Eclipse?

I have to create several proxies, to add, for example, logging. Something like that: interface IMath { public int add(a, b); } class Math implements IMath { public int add(a, b) { return a + ...
Yuriy Kulikov's user avatar
22 votes
3 answers
8k views

Fast implement wrapping (delegate methods) in Eclipse?

Is there some template or something to implement iterface methods with accessing to wrapped member? For example, suppose I have public class MyClass implements List<Something> { private ...
Suzan Cioc's user avatar
  • 29.8k
22 votes
1 answer
15k views

Using Streams with primitives data types and corresponding wrappers

While playing around with Java8's Streams-API, I stumbled over the following: To convert an array of primitive wrapper classe objects into a Stream I just have to call Stream.of(array). But to ...
ifloop's user avatar
  • 8,306
21 votes
3 answers
13k views

Fragments - Do you have to use an Activity Wrapper around a fragment which comprises the whole Activity?

Consider the sample app from developers.android.com This describes using Fragments like so: On a Phone you can use Fragment 1 on Activity A and fragment 2 on Activity B. On a tablet you have more ...
Graeme's user avatar
  • 25.8k
21 votes
8 answers
11k views

Comparing wrapper class with primitive using equals() gives strange behavior

Consider below code snap. we use equals() to compare objects are meaningfully equivalent or not ? Here both value are meaningfully equal but why does longWrapper.equals(0) return false ? And when I ...
Snehal Patel's user avatar
  • 1,310
21 votes
4 answers
60k views

Tesseract 3 (OCR) - .NET Wrapper

http://code.google.com/p/tesseractdotnet/ I am having a problem getting Tesseract to work in my Visual Studio 2010 projects. I have tried console and winforms and both have the same outcome. I have ...
Jpin's user avatar
  • 1,537
20 votes
7 answers
8k views

Why Java does not allow null while declaring primitive data types [duplicate]

This is in continuation to my previous question and accroding to answers of this question Declaration of wrapper classes Java wraps primitive data type to wrapper classes then why char c = null; // ...
Vishrant's user avatar
  • 16.2k
20 votes
6 answers
16k views

Are Java wrapper classes really immutable?

Java Wrapper classes are supposed to be immutable. This means that once an object is being created, e.g., Integer i = new Integer(5); its value cannot be changed. However, doing i = 6; is ...
PetrosB's user avatar
  • 4,144

1
2 3 4 5
74